#1419. Cyclically Isomorphic

Cyclically Isomorphic

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 TT(1T51 \le T \le 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 (1nm1051 \le n \cdot m \le 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 (1Q1051 \le Q \le 10^5).

Each of the next QQ lines contains two integers xx, yy (1x,yn1 \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'.

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