#include <bits/stdc++.h>
using namespace std;
int n, m, q, a[201][201];
int dx[300], dy[300];
bool visit[201][201][80];
struct node {
  int x, y, f;
};
node f[201][201][80];
node dfs(int x, int y, int z) {
  if (visit[x][y][z]) return f[x][y][z];
  visit[x][y][z] = 1;
  int xx = x + dx[a[x][y]];
  int yy = y + dy[a[x][y]];
  if (xx >= n || yy >= m || xx < 0 || yy < 0) {
    xx = x;
    yy = y;
  }
  if (a[xx][yy] == z) {
    node temp;
    temp.x = xx;
    temp.y = yy;
    temp.f = 1;
    return f[x][y][z] = temp;
  }
  return f[x][y][z] = dfs(xx, yy, z);
}
void init() {
  node temp;
  temp.x = -1;
  temp.y = -1;
  temp.f = 0;
  char t;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    getchar();
    for (int j = 0; j < m; j++) {
      t = getchar();
      a[i][j] = t;
      for (int k = '0'; k <= '9'; k++) f[i][j][k] = temp;
    }
  }
  for (int i = '0'; i <= '9'; i++) cin >> dx[i] >> dy[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = '0'; k <= '9'; k++) f[i][j][k] = dfs(i, j, k);
}
int main() {
  init();
  string s;
  bool flag = true;
  getchar();
  map<string, bool> mp;
  while (q--) {
    cin >> s;
    flag = false;
    if (!mp.count(s)) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (flag) break;
          if (s[0] == a[i][j]) {
            flag = true;
            int h = 1, x = i, y = j;
            while (flag && h < s.length()) {
              if (f[x][y][s[h]].f == 1) {
                int xx = x, yy = y;
                x = f[xx][yy][s[h]].x;
                y = f[xx][yy][s[h]].y;
                h++;
              } else
                flag = false;
            }
          }
        }
        if (flag) break;
      }
      mp[s] = flag;
    }
    flag = mp[s];
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
