e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
Problems

Playing the fool

Playing the fool

As you have learned, Peter loves to program. He recently decided to implement the popular card game "Fool". But Petit has much experience, he urgently needs your help.

As you know, "Fool" play a deck of36In Petya's program, each card appears as a string of two characters, where the first symbol indicates the rank ('6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A') cards, and the second character means a suit ('S', 'C', 'D', 'H'). The ranks are listed in ascending order of seniority.

Pete must solve the following problem: whether a player, having a set ofNcards, recaptureMcards, which under him made a move? In order to defend himself, a player must cover each of the cards, which under him make a move card from his deck. The card can cover either the highest card of the same suit, or trump suit card. If you react with itself is a trump card, it can cover only senior trump. One card can cover only one card.

Input

The first line of the input file contains a number of tests. Each test consists of three rows. On the first line of each test are two integersN and M (1 <= N <= 35, 1 <= M <= 4, M <= N), as well as a symbol ofR, meaning the trump suit. On the second line of the test are listedNcards from a player's hand. On the next line of the test are listedMcards, which must be repelled. All the cards that you want to recapture, will have one rank.

Output

For each test should bring "YES" if you can fight off, or "NO", if you can not.

Time limit 1 second
Memory limit 64 MiB
Input example #1
2
6 2 C
KD KC AD 7C AH 9C
6D 6C
4 1 D
9S KC AH 7D
8D
Output example #1
YES
NO