Akhil and his girlfriend

0

0 votes
Easy-Medium
Problem

Akhil was writing a love letter to his girlfriend Sapna. But while writing the letter he was called by his mother. In the meantime, his brother transformed all occurrences of some letter to some other letter in a particular order.

For example - If the original string is "abca". He first changes 'a'->'d', string becomes "dbcd", then changes 'b'->'t', the string becomes "dtcd".

After much scolding by Akhil, his brother reveals the alphabet transformations (in that order).

Also his brother claims that no occurence of final letter was present during the change. For example, if he changes 'a' to 'b', then no 'b' was present in the string just before the change.

Is the claim true?

Input Format:-
First line will contain T, i.e. number of test cases. First line of every test case will contain a lower-case string s, which is the string after the transformations. Second line of every test case will contain an integer M. Next M will contain two space-separated characters each, representing the original character and new character respectively.

Output Format:-
Output in new line for every test case, "Yes" if the claim is true, else "No" .

Constraints:-
1 ≤ T ≤ 10
1 ≤ length of string (S) ≤
1 ≤ M

Sample Input
3
tact
4
a d
b k
k a
d t
kaak
4
a k
b c
c d
d a
attat
3
c k
b k
k t
Sample Output
Yes
Yes
No
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?