Escape the Maze with a Drill

No attempts yetTime limit1sMemory limit128 MB

Problem

A robot is trapped in a maze shaped as an M×NM \times N grid. Each cell is either empty or a wall. The robot cannot step onto a wall directly, and it can never leave the maze because the outer boundary is solid. The robot does carry a drill, however: spending 11 unit of energy turns one wall cell into an empty cell, after which the robot may enter it.

The robot starts at a given cell and wants to reach a destination cell. In one step it moves to a cell that is horizontally or vertically adjacent. Entering an empty cell is free, but entering a wall cell requires first drilling that wall, which costs 11 unit of energy. The robot has a limited amount of stored energy.

Given the map of the maze and the amount of stored energy, decide whether the robot can reach the destination.

Input

The first line contains an integer TT (1T201 \le T \le 20), the number of test cases.

Each test case is given as follows. The first line contains an integer kk (k0k \ge 0), the amount of energy stored in the robot. The next line contains two integers MM and NN (1M5001 \le M \le 500, 1N5001 \le N \le 500), the number of rows and columns of the maze. Each of the following MM lines contains exactly NN characters describing one row of the maze. The character * is a wall and . is an empty cell. S marks the robot start and T marks the destination. Every symbol on a maze row is separated from the next by at least one whitespace character.

Output

For each test case, print a single line containing y if the robot can reach the destination while spending at most kk units of energy, or n otherwise.