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