Wilbur the pig now wants to play with strings. He has found an n by m table consisting only of the digits from 0 to 9 where the rows are numbered 1 to n and the columns are numbered 1 to m. Wilbur starts at some square and makes certain moves. If he is at square (x, y) and the digit d (0 ≤ d ≤ 9) is written at position (x, y), then he must move to the square (x + ad, y + bd), if that square lies within the table, and he stays in the square (x, y) otherwise. Before Wilbur makes a move, he can choose whether or not to write the digit written in this square on the white board. All digits written on the whiteboard form some string. Every time a new digit is written, it goes to the end of the current string.

Wilbur has q strings that he is worried about. For each string si, Wilbur wants to know whether there exists a starting position (x, y) so that by making finitely many moves, Wilbur can end up with the string si written on the white board.

Input

The first line of the input consists of three integers n, m, and q (1 ≤ n, m, q ≤ 200) — the dimensions of the table and the number of strings to process, respectively.

Each of the next n lines contains m digits from 0 and 9 giving the table itself.

Then follow 10 lines. The i-th of them contains the values ai - 1 and bi - 1 ( - 200 ≤ ai, bi ≤ 200), i.e. the vector that Wilbur uses to make a move from the square with a digit i - 1 in it.

There are q lines that follow. The i-th of them will contain a string si consisting only of digits from 0 to 9. It is guaranteed that the total length of these q strings won't exceed 1 000 000.

Output

For each of the q strings, print "YES" if Wilbur can choose x and y in order to finish with this string after some finite number of moves. If it's impossible, than print "NO" for the corresponding string.

Examples

Input

1 1 2
0
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
0000000000000
2413423432432


Output

YES
NO


Input

4 2 5
01
23
45
67
0 1
0 -1
0 1
0 -1
0 1
0 -1
0 1
0 -1
0 1
0 -1
0000000000
010101011101
32232232322
44343222342444324
6767


Output

YES
YES
YES
NO
YES

Note

In the first sample, there is a 1 by 1 table consisting of the only digit 0. The only move that can be made is staying on the square. The first string can be written on the white board by writing 0 repeatedly. The second string cannot be written as there is no 2 on the table.
#include <bits/stdc++.h>
using namespace std;
int INF = 0x3f3f3f3f;
long long mod = 1e9 + 7;
const int N = 205;
int a[N][N];
int dx[10], dy[10];
pair<int, int> dp[N][N][10];
int vis[N][N];
vector<pair<int, int>> E;
int n, m, q;
void dfs(int x, int y) {
  vis[x][y] = 1;
  int t = a[x][y];
  int tx = x + dx[t];
  int ty = y + dy[t];
  if (tx >= 1 && tx <= n && ty >= 1 && ty <= m) {
    dp[x][y][t] = {tx, ty};
    if (vis[tx][ty] == 0) {
      dfs(tx, ty);
    }
    for (int i = 0; i < 10; i++) {
      if (i != t) dp[x][y][i] = dp[tx][ty][i];
    }
  } else {
    dp[x][y][t] = {x, y};
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%1d", &a[i][j]);
    }
  }
  for (int i = 0; i < 10; i++) {
    scanf("%d%d", &dx[i], &dy[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (vis[i][j] == 0) {
        dfs(i, j);
        E.push_back({i, j});
      }
    }
  }
  while (q--) {
    string s;
    cin >> s;
    for (int i = 0; i < E.size(); i++) {
      int x = E[i].first, y = E[i].second;
      for (int k = 0; k < s.size(); k++) {
        pair<int, int> tmp = dp[x][y][s[k] - '0'];
        if (tmp.first == 0) {
          goto M1;
        }
        x = tmp.first, y = tmp.second;
      }
      puts("YES");
      goto M2;
    M1:;
    }
    puts("NO");
  M2:;
  }
  return 0;
}
