#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int q;
int a[202][202];
pair<int, int> co[202 * 202];
pair<int, int> ope[202];
int id[202][202];
vector<int> v[202 * 202];
int use[202 * 202];
int u_s;
int belong[202 * 202];
unordered_set<int> p[202 * 202];
int siz = 0;
unordered_set<int> bak;
int fp;
bool connected[202 * 202];
inline int dfs(int b) {
  use[b] = u_s;
  for (int i = 0; i < v[b].size(); i++) {
    if (use[v[b][i]] == u_s) {
      belong[b] = siz;
      p[siz].insert(a[co[b].first][co[b].second]);
      siz++;
      if (v[b][i] == b) {
        return -1;
      }
      return v[b][i];
    } else {
      if (belong[v[b][i]] != -1) {
        connected[belong[v[b][i]]] = true;
        return -1;
      }
      if (use[v[b][i]]) {
        bak.erase(v[b][i]);
        return -1;
      }
      int r = dfs(v[b][i]);
      if (r == -1) {
        r = -1;
      } else {
        belong[b] = siz - 1;
        p[siz - 1].insert(a[co[b].first][co[b].second]);
        if (r == b) {
          r = -1;
        }
      }
      if (belong[b] == -1 && belong[v[b][i]] != -1) {
        connected[belong[v[b][i]]] = true;
      }
      return r;
    }
  }
}
vector<pair<string, int> > vv;
char buf[1000002];
int all_cnt[12];
int S;
int minu[12];
bool match(int ind) {
  int ind2 = 0;
  for (int i = 0; i < 10; i++) {
    minu[i] = 0;
  }
  for (int i = 0; ind2 < S && i < vv[ind].first.size(); i++) {
    if (buf[ind2] == vv[ind].first[i]) {
      ind2++;
      minu[vv[ind].first[i] - '0']++;
    }
  }
  if (ind2 == S) {
    return true;
  }
  for (int i = 0; i < 10; i++) {
    if (all_cnt[i] - minu[i]) {
      if (p[vv[ind].second].count(i)) {
      } else {
        return false;
      }
    }
  }
  return true;
}
int main() {
  cin >> n >> m >> q;
  {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      scanf("%s", buf);
      for (int j = 0; j < m; j++) {
        a[i][j] = buf[j] - '0';
        id[i][j] = cnt;
        co[cnt] = make_pair(i, j);
        cnt++;
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    scanf("%d%d", &ope[i].first, &ope[i].second);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ii = i + ope[a[i][j]].first;
      int jj = j + ope[a[i][j]].second;
      if (ii >= 0 && jj >= 0 && ii < n && jj < m) {
        v[id[i][j]].push_back(id[ii][jj]);
      } else {
        v[id[i][j]].push_back(id[i][j]);
      }
    }
  }
  memset(belong, -1, sizeof(belong));
  for (int i = 0; i < n * m; i++) {
    u_s++;
    if (use[i] == 0) {
      fp = i;
      bak.insert(fp);
      dfs(i);
    }
  }
  for (auto ite = bak.begin(); ite != bak.end(); ite++) {
    int b = (*ite);
    if (belong[b] != 1 && connected[belong[b]]) {
      continue;
    }
    vv.push_back(make_pair(string(), 0));
    while (belong[b] == -1) {
      vv.back().first.push_back(a[co[b].first][co[b].second] + '0');
      b = v[b][0];
    }
    vv.back().second = belong[b];
  }
  while (q--) {
    scanf("%s", buf);
    S = strlen(buf);
    for (int i = 0; i < 10; i++) {
      all_cnt[i] = 0;
    }
    for (int i = 0; i < S; i++) {
      all_cnt[buf[i] - '0']++;
    }
    bool ok = false;
    for (int i = 0; i < vv.size(); i++) {
      if (match(i)) {
        ok = true;
        break;
      }
    }
    if (ok) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
  return 0;
}
