Check if its a Check

5

1 votes
Problem

In a game of chess, Check is a game position in which a player's King is under attack by any of the opponent's pieces.

Bob is playing with Chess pieces. He randomly arranges three pieces on 8x8 chessboard: a black's King , a white's King and any one of the white's Queen, Knight, Bishop or Rook. Positions of these pieces are known to us (positions are described following the standard chess notations) . Bob is interested in finding if black's King is under 'check' or not?

Input:
First line contains integer T - number of test cases. Each test case contains two lines. First line contains two strings describing the positions of black's King and white's King Second line contains either q, k, b, or r and its position. (q = queen, k = knight, b = bishop and r = rook)

Output:
For each test case print "check"(without quotes) if black's King is under 'check' else print "-1"(without quotes)

Constraints:
1<=T<=10
Each position is a two character alpha-numeric string.
All positions in a test case will be different.
First character of each position will be a lower-case alphabet in the range [a,h] and second character will be an integer in the range [1,8]

Sample tests explanation: enter image description here

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?