#P7625. [2018年杭电多校]K-Similar Strings
[2018年杭电多校]K-Similar Strings
K-Similar Strings
Problem Description
Acesrc loves solving string problems. He defined a relation called between two strings. The definition of -similarity is shown below:
- for nonempty string , and are -similar;
- for two nonempty strings and with , if and are -similar ( denotes string concatenation), then and are -similar;
- if and are -similar, then and are -similar, where and are arbitrary (possibly empty) strings;
- if and are -similar, and are -similar, then and are -similar. For example, and are 3-similar according to the the first condition. Hence, and are 3-similar according to the second condition. Moreover, and , and are also 3-similar, respectively, according to the third condition. Finally, and are 3-similar, according to the fourth condition. Now, given two strings and an integer , please determine whether and are -similar.
Input
The first line of the input is a single integer , denoting the number of test cases. Each test case contains three lines, which represent , , , respectively. It is guaranteed that and contain only lowercase letters 'a'-'z' and the lengths of and are between 1 and , inclusive. It is further guaranteed that the sum of lengths of and in all test cases does not exceed .
Output
For each test case, display a single line: if and are -similar, or if they are not.
Sample Input
4
3
ba
baa
2
aab
ab
1
acesrc
acesrc
100
roundgod
zyb
Sample Output
yes
no
yes
no
Source
2018 Multi-University Training Contest 8