All Tracks Problem

Akhil and his girlfriend
Tag(s):

Easy-Medium

Problem
Editorial
Analytics

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) ≤ \(10^{4}\)
1 ≤ M\(10^{4}\)

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.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

National Institute of Technology Jalandhar

Challenge Name

Sprint Challenge 1

OTHER PROBLEMS OF THIS CHALLENGE
通知
View All Notifications

?