#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 41;
int n, node[222][222], m, q, maps[10][2];
pair<int, int> table[222][222][11];
bool check[222][222][11];
pair<int, int> digui(int x, int y, int z) {
  if (table[x][y][z] != pair<int, int>(-1, -1)) return table[x][y][z];
  if (check[x][y][z]) return table[x][y][z] = pair<int, int>(-1, -2);
  check[x][y][z] = true;
  int u = x + maps[node[x][y]][0];
  int vs = y + maps[node[x][y]][1];
  if (u < 0 || u >= n || vs < 0 || vs >= m) {
    for (int i = 0; i < 10; i++) {
      table[x][y][i] = pair<int, int>(-1, -2);
    }
    table[x][y][node[x][y]] = pair<int, int>(x, y);
    return table[x][y][z];
  }
  if (node[u][vs] == z) return table[x][y][z] = pair<int, int>(u, vs);
  return table[x][y][z] = digui(u, vs, z);
}
void solve(void) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 10; k++) {
        digui(i, j, k);
      }
    }
  }
  map<string, bool> answer;
  while (q--) {
    string input;
    cin >> input;
    bool kaiguan = false;
    if (!answer.count(input)) {
      int size = input.size();
      int k = 1;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (input[k - 1] - '0' == node[i][j]) {
            pair<int, int> cur(i, j);
            while (k < size) {
              if (table[cur.first][cur.second][input[k] - '0'] >
                  pair<int, int>(-1, -1)) {
                cur = table[cur.first][cur.second][input[k] - '0'];
                k++;
              } else
                break;
            }
            if (k == size) kaiguan = true;
            k = 1;
          }
        }
        if (kaiguan) break;
      }
      answer[input] = kaiguan;
    }
    kaiguan = answer[input];
    if (kaiguan)
      puts("YES");
    else
      puts("NO");
  }
}
int main(void) {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++) {
    char input[222];
    cin >> input;
    for (int j = 0; j < m; j++) {
      node[i][j] = input[j] - '0';
      for (int k = 0; k < 10; k++) {
        table[i][j][k] = pair<int, int>(-1, -1);
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    scanf("%d%d", &maps[i][0], &maps[i][1]);
  }
  solve();
  return 0;
}
