#1419. Cyclically Isomorphic
Cyclically Isomorphic
If there exists an integer such that string becomes equal to string after being cyclically right-shifted by positions, then the strings and are said to be cyclically right-shifted.
Now, given strings of length consisting of lowercase letters, there are a total of queries. Each query provides two positive integers and . If the strings and are cyclically right-shifted, output Yes
; otherwise, output No
.
Input
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains two integers and () — the number of the strings and the length of strings.
Each of the next lines contains a string of lowercase letters .
The next line contains a positive integer ().
Each of the next lines contains two integers , () asks whether the string and the string are cyclic isomorphic.
Output
For each test case, output lines. Each line should contain a string indicating whether the current query strings and are cyclically isomorphic. If they are cyclically isomorphic, output Yes
; otherwise, output 'No'.
Example
2
2 2
ab
ba
1
1 2
4 3
aab
baa
bba
bab
6
1 2
1 3
1 4
2 3
2 4
3 4
Yes
Yes
No
No
No
No
Yes
Limitation
Time limit: 2 seconds
Memory limit: 512 megabytes