Long time ago one man said, that he had explored the corridors of one cave. It means, that he was in all corridors of the cave. Corridors are horizontal or vertical segments. A corridor is counted as visited if he was in at least one point of corridor.
Now you want to know, if it is true. You have a map of the cave, and you know that explorer used the following algorithm: he turns left if he can, if he can't he goes straight, if he can't he turns right, if he can't he turns back. Exploration ends when the man reaches entry point second time. Your task is to count how many corridors weren't visited by explorer.
In the first line there is an integer (T \le 20) - the number of different maps. For each map in first line there is an integer (N \le 1000) - the number of corridors. It is known that no two vertical corridors have common point and no two horizontal corridors have common point. So the next lines contain such information: the line starts with one of the characters or - vertical or horizontal corridor. Then one -coordinate and two -coordinates are given for a horizontal corridor or one -coordinate and two -coordinates for a vertical corridor. The last line for each map contains and coordinates of the entry point (start and end point of travel) and the direction ( - left, - right, - up and - down). You may assume that: entry point is not located in the cross-point of two corridors, and explorer can always move forward by the direction given in the input. All coordinates are integers and do not exceed by absolute value and there is no more than vertical corridors and no more than horizontal corridors.
For each map the program has to print the number of unvisited corridors in separate line.
Example 1