Stealth Ninja#3120

Stealth Ninja

2 seconds
64 megabytes
Medium

A large palace contains a hall, where the floor is a (2n-1) \times (2n-1) grid of squares, arranged in (2n-1) rows (numbered from to 2n-1) and (2n-1) columns (numbered from to 2n-1) — as shown in the figure below for n = 4. Each square that is at the intersection of an even-numbered row and an even-numbered column is covered by a square wooden support column. The other squares are empty. Thus, between the walls and the wooden supports, there are corridors from left to right and corridors from back to front through the hall. At the ends of the back-to-front corridors, there are door openings with curtains. Otherwise, the walls are closed.

The hall is guarded by guards. Each guard is stationed at the intersection of a front-to-back and a left-to-right corridor. Each guard looks for seconds to the left, seconds to the back, seconds to the right, and seconds to the front, repeating this process indefinitely. The viewing directions of the guards are not necessarily synchronized: while some may look left, others may look forward.

A ninja must traverse the hall from the front to the back without being seen by the guards. Before entering the hall, the ninja waits in row , that is, behind one of the curtains in the door openings in the front wall. The ninja can choose behind which curtain to wait and how long to wait before entering the hall. The ninja can choose any door in the back wall as the exit. To move between two adjacent squares, the ninja needs exactly seconds — while moving, the ninja can be seen by any guard who is currently watching in that direction. Can the ninja successfully traverse the hall? The guards can see past each other, but not through the curtains.

Figure 1 shows how the ninja finds a way out. First, the ninja waits. After seconds, the guard in row , column turns to the left, and the ninja steps out from behind the curtain. After seconds, the ninja arrives at row , column . After seconds, the ninja arrives at row , column . The ninja waits until the guard at row , column turns to the back; then the ninja starts moving and disappears behind the curtain in column just before the guard in row turns toward that direction.

Input

The first line contains the number of test cases. Each test case has the following format:

  • The first line contains two numbers: (the number of corridors in each direction, 1 \leq n \leq 250) and (the number of guards, 0 \leq k \leq 500).

  • lines, one for each guard: each line contains an odd number (1 \leq r \leq 2n-1), an odd number (1 \leq c \leq 2n-1), and one of the letters , , or . The first number is the row in which the guard is placed; the second number is the column in which the guard is placed; the letter indicates the direction the guard is looking at time zero (left, back, right, or front).

There may not be more than one guard in any position of the hall.

Output

For each test case, output a single line with either succeeds or fails.

Examples

Example 1

Loading
Loading