CF BUDDY
← Problems·

1948C · Arrow Path

1300 · brute force, constructive algorithms, dfs and similar

Problem: There is a grid, consisting of 22 rows and nn columns. The rows are numbered from 11 to 22 from top to bottom. The columns are numbered from 11 to nn from left to right. Each cell of the grid contains an arrow pointing either to the left or to the right. No arrow points outside the grid.

There is a robot that starts in a cell (1,1)(1, 1). Every second, the following two actions happen one after another:

  1. Firstly, the robot moves left, right, down or up (it can't try to go outside the grid, and can't skip a move);
  2. then it moves along the arrow that is placed in the current cell (the cell it ends up after its move).

Your task is to determine whether the robot can reach the cell (2,n)(2, n).

Input Format: The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer (2n21052 \le n \le 2 \cdot 10^5).

The second line contains a string consisting of exactly nn characters < and/or > — the first row of the grid.

The third line contains a string consisting of exactly nn characters < and/or > — the second row of the grid.

Additional constraints on the input:

  • nn is even;
  • there are no arrows pointing outside the grid;
  • the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

Output Format: For each test case, print YES if the robot can reach the cell (2,n)(2, n); otherwise, print NO.

You can print each letter in any case. For example, yes, Yes, YeS will all be recognized as positive answer.

Note: In the first example, one of the possible paths looks as follows: (1,1)(1,2)(1,3)(2,3)(2,4)(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (2, 4).

In the second example, one of the possible paths looks as follows: (1,1)(2,1)(2,2)(1, 1) \rightarrow (2, 1) \rightarrow (2, 2).

In the third example, there is no way to reach the cell (2,4)(2, 4).

In the fourth example, one of the possible paths looks as follows: (1,1)(2,1)(2,2)(1,2)(1,3)(2,3)(2,4)(2,5)(2,6)(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (2, 5) \rightarrow (2, 6).

Sample Cases

Case 1

Input

4
4
>><<
>>><
2
><
><
4
>>><
>><<
6
>><<><
><>>><

Output

YES
YES
NO
YES

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback