#P9796. Cyclically Isomorphic

Cyclically Isomorphic

Cyclically Isomorphic

Problem Description

If there exists an integer kk such that string SS becomes equal to string TT after being cyclically right-shifted by kk positions, then the strings SS and TT are said to be cyclically right-shifted. Now, given nn strings of length mm consisting of lowercase letters , there are a total of QQ queries. Each query provides two positive integers xx and yy. If the strings sxs_x and sys_y are cyclically right-shifted , output 'Yes'; otherwise, output 'No'.

Input

The input consists of multiple test cases. The first line contains a single integer T(1T5)T(1≤T≤5) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers nn and mm (1n×m105)(1≤n\times m≤10^5) — the number of the strings and the length of strings. Each of the next nn lines contains a string of lowercase letters sis_i。 The next line contains a positive integer QQ (1Q105)(1\le Q\le 10^5)。 Each of the next QQ lines contains two integers x,yx,y (1x,yn)(1\le x,y\le n) asks whether the string sxs_x and the string sys_y are cyclic isomorphic.

Output

For each test case, output QQ lines. Each line should contain a string indicating whether the current query strings sxs_x and sys_y are cyclically isomorphic. If they are cyclically isomorphic, output 'Yes'; otherwise, output 'No'.

Sample Input

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

Sample Output

Yes
Yes
No
No
No
No
Yes

Source

2023“钉耙编程”中国大学生算法设计超级联赛(1)