beecrowd | 1206

# Challenge of St. Petersburg

By Marcio T. I. Oshiro  Brazil

Timelimit: 1

The Russia has always been the cradle of great chess masters. Few people know that the FIDE (World Chess Federation), which is the highest body regulating the game of chess was founded in 1924 from a movement begun 10 years before in the world championship of the sport that took place in St. Petersburg in 1914. Today, the top 10 players in the world, according to FIDE, three are Russians.

The tournament of St. Petersburg was also known by the attempts of the great masters of popularizing the game. At the time the greatest masters (like Capablanca) took to the streets to propose challenges for people in order to interest them to practice the game. One of these challenges was known as the Challenge of St. Petersburg. The great master rode a situation where the white pieces had only the king, and the goal was the person who said if the white king was or not in checkmate.

In the situation described above, the white king is checkmated if he is being attacked, and every move he makes leads him to a square that is also being attacked.

What you need to know about chess

Consider that initially the black chess pieces are at lines 7 and 8 while the white chess pieces starts at lines 1 and 2. There aren’t two chess pieces in the same square. The chess pieces considered in the problem (pawn, rook, bishop, queen and king) can’t go over to other parts, in other words, if during chess pieces’ movement there is any other chess piece on its way you must stop before or attacking the chess piece (if it is the opponent), taking its place. The movement and the attack of each type of chess peace are as follows:

# Pawn: walking just one square forward (toward the line 1) can attack in any of the two diagonals immediately in front;
# Rook: walk / attacks how many squares you want horizontally or vertically;
# Bishop: walking / attacking how many squares you want diagonally;
# Queen: walk / attacks how many squares you want horizontally or vertically, or diagonally;
# King: walk / attacks just a square or horizontally, or vertically, or diagonally.

## Input

The input consists of several test cases and ends with the end of file (EOF). The first line of each test case contains one integer N (2 ≤ N ≤ 10) indicating the number of black chess pieces. The next line contains the description of the positions of N black chess peaces separated by a space. The third line contains the description of the white king.

A description of one chess piece consists of 3 characters. The first indicates whether the chess piece is a pawn (P)(Peão), rook(T)(Torre), Bishop (B)(Bispo), Queen(R)(Rainha) or King (W)(Rei). Note that the great master did not use horses to facilitate who was still just learning the game. The second character between 'a' and 'h', indicates the column in which the chess peace is and the third, from '1 'to '8' indicates the line.

Neither of the test cases is the situation in which the white king and the black king are adjacent.

## Output

For each test case, print a line with the word SIM (YES) if the white king is in checkmate, or the word NAO (NO), otherwise.

 Sample Input Sample Output 4 Tc3 Te4 Bf4 Wa8 Wd1 5 Wb5 Pf3 Rh7 Te1 Tg1 Wh1 4 Wa8 Ta1 Ta3 Rd2 We2 NAO SIM NAO