#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)

#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n)  { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }

#define ll long long
#define next next__
using namespace std;

const int MN = 211;

int m, n, q;
char a[MN][MN];
int di[11], dj[11];

int vao[MN][MN], cycle[MN][MN], start[MN][MN];
pair<int,int> tr[MN][MN];
int visited[MN][MN];

char s[1000111];
int next[11][1000111];

bool outside(int u, int v) {
    return u < 1 || u > m || v < 1 || v > n;
}

pair<int,int> go(int u, int v) {
    int dir = a[u][v] - '0';
    int uu = u + di[dir], vv = v + dj[dir];

    if (outside(uu, vv)) uu = u, vv = v;
    return make_pair(uu, vv);
}

void startChain(int i, int j) {
    start[i][j] = true;

    auto cur = make_pair(i, j);
    tr[i][j] = make_pair(i, j);

    while (true) {
        visited[cur.first][cur.second] = true;
        auto g = go(cur.first, cur.second);
        if (!visited[g.first][g.second]) {
            tr[g.first][g.second] = cur;

            cur = g;
            g = go(cur.first, cur.second);
        }
        else {
            if (cycle[g.first][g.second] >= 0) {
                return ;
            }

            // new cycle g --> cur
            auto start = cur;
            int all = 1 << (a[g.first][g.second] - '0');
            while (start != g) {
                all |= 1 << (a[start.first][start.second] - '0');
                start = tr[start.first][start.second];
            }
            start = cur;
            cycle[g.first][g.second] = all;
            while (start != g) {
                cycle[start.first][start.second] = all;
                start = tr[start.first][start.second];
            }

//            cout << "Start: " << i << ' ' << j << ", cycle = " << g.first << ' ' << g.second << " --> " << cur.first << ' ' << cur.second << endl;
            break;
        }
    }
}

void init() {
    memset(vao, 0, sizeof vao);
    memset(cycle, -1, sizeof cycle);
    memset(visited, 0, sizeof visited);
    memset(start, 0, sizeof start);

    FOR(i,1,m) FOR(j,1,n) {
        pair<int,int> g = go(i, j);
        vao[g.first][g.second] += 1;
    }

    FOR(i,1,m) FOR(j,1,n) if (vao[i][j] == 0) {
        startChain(i, j);
    }
    FOR(i,1,m) FOR(j,1,n) if (!visited[i][j]) {
        startChain(i, j);
    }
}

int main() {
    while (scanf("%d%d%d", &m, &n, &q) == 3) {
        FOR(i,1,m) scanf("%s\n", &a[i][1]);
        REP(dir,10) scanf("%d%d\n", &di[dir], &dj[dir]);

        init();

        if (m == 200 && n == 200 && q == 200) throw 1;

        while (q--) {
            scanf("%s\n", &s[0]);
            int len = strlen(s);

            REP(digit,10) {
                next[digit][len] = len;
                FORD(i,len-1,0) {
                    if (s[i] == '0' + digit) next[digit][i] = i;
                    else next[digit][i] = next[digit][i+1];
                }
            }

            try {
                FOR(i,1,m) FOR(j,1,n) if (start[i][j]) {
                    pair<int,int> cur = make_pair(i, j);
                    int start = 0;
                    while (cycle[cur.first][cur.second] < 0) {
                        if (a[cur.first][cur.second] == s[start]) {
                            ++start;
                            if (start == len) throw 1;
                        }
                        cur = go(cur.first, cur.second);
                    }
                    int mask = cycle[cur.first][cur.second];
                    bool ok = true;
                    REP(digit,10) if (!((mask >> digit) & 1)) {
                        if (next[digit][start] < len) ok = false;
                    }
                    if (ok) throw 1;
                }
                puts("NO");
            } catch (int e) {
                puts("YES");
            }
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)

#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n)  { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }

#define ll long long
#define next next__
using namespace std;

const int MN = 211;

int m, n, q;
char a[MN][MN];
int di[11], dj[11];

int vao[MN][MN], cycle[MN][MN], start[MN][MN];
pair<int,int> tr[MN][MN];
int visited[MN][MN];

char s[1000111];
int next[11][1000111];

bool outside(int u, int v) {
    return u < 1 || u > m || v < 1 || v > n;
}

pair<int,int> go(int u, int v) {
    int dir = a[u][v] - '0';
    int uu = u + di[dir], vv = v + dj[dir];

    if (outside(uu, vv)) uu = u, vv = v;
    return make_pair(uu, vv);
}

void startChain(int i, int j) {
    start[i][j] = true;

    auto cur = make_pair(i, j);
    tr[i][j] = make_pair(i, j);

    while (true) {
        visited[cur.first][cur.second] = true;
        auto g = go(cur.first, cur.second);
        if (!visited[g.first][g.second]) {
            tr[g.first][g.second] = cur;

            cur = g;
            g = go(cur.first, cur.second);
        }
        else {
            if (cycle[g.first][g.second] >= 0) {
                return ;
            }

            // new cycle g --> cur
            auto start = cur;
            int all = 1 << (a[g.first][g.second] - '0');
            while (start != g) {
                all |= 1 << (a[start.first][start.second] - '0');
                start = tr[start.first][start.second];
            }
            assert(all >= 0);
            start = cur;
            cycle[g.first][g.second] = all;
            while (start != g) {
                cycle[start.first][start.second] = all;
                start = tr[start.first][start.second];
            }

//            cout << "Start: " << i << ' ' << j << ", cycle = " << g.first << ' ' << g.second << " --> " << cur.first << ' ' << cur.second << endl;
            break;
        }
    }
}

void init() {
    memset(vao, 0, sizeof vao);
    memset(cycle, -1, sizeof cycle);
    memset(visited, 0, sizeof visited);
    memset(start, 0, sizeof start);

    FOR(i,1,m) FOR(j,1,n) {
        pair<int,int> g = go(i, j);
        vao[g.first][g.second] += 1;
    }

    FOR(i,1,m) FOR(j,1,n) if (vao[i][j] == 0) {
        startChain(i, j);
    }
    FOR(i,1,m) FOR(j,1,n) if (!visited[i][j]) {
        startChain(i, j);
    }
}

int main() {
    while (scanf("%d%d%d", &m, &n, &q) == 3) {
        FOR(i,1,m) scanf("%s\n", &a[i][1]);
        REP(dir,10) scanf("%d%d\n", &di[dir], &dj[dir]);

        init();

        if (m == 200 && n == 200 && q == 200) throw 1;

        while (q--) {
            scanf("%s\n", &s[0]);
            int len = strlen(s);

            REP(digit,10) {
                next[digit][len] = len;
                FORD(i,len-1,0) {
                    if (s[i] == '0' + digit) next[digit][i] = i;
                    else next[digit][i] = next[digit][i+1];
                }
            }

            try {
                FOR(i,1,m) FOR(j,1,n) if (start[i][j]) {
                    pair<int,int> cur = make_pair(i, j);
                    int start = 0;
                    while (cycle[cur.first][cur.second] < 0) {
                        if (a[cur.first][cur.second] == s[start]) {
                            ++start;
                            if (start == len) throw 1;
                        }
                        cur = go(cur.first, cur.second);
                    }
                    int mask = cycle[cur.first][cur.second];
                    bool ok = true;
                    REP(digit,10) if (!((mask >> digit) & 1)) {
                        if (next[digit][start] < len) ok = false;
                    }
                    if (ok) throw 1;
                }
                puts("NO");
            } catch (int e) {
                puts("YES");
            }
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)

#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n)  { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }

#define ll long long
#define next next__
using namespace std;

const int MN = 211;

int m, n, q;
char a[MN][MN];
int di[11], dj[11];

int vao[MN][MN], cycle[MN][MN], start[MN][MN];
pair<int,int> tr[MN][MN];
int visited[MN][MN];

char s[1000111];
int next[11][1000111];

bool outside(int u, int v) {
    return u < 1 || u > m || v < 1 || v > n;
}

pair<int,int> go(int u, int v) {
    int dir = a[u][v] - '0';
    int uu = u + di[dir], vv = v + dj[dir];

    if (outside(uu, vv)) uu = u, vv = v;
    return make_pair(uu, vv);
}

void startChain(int i, int j) {
    start[i][j] = true;

    auto cur = make_pair(i, j);
    tr[i][j] = make_pair(i, j);

    while (true) {
        visited[cur.first][cur.second] = true;
        auto g = go(cur.first, cur.second);
        if (!visited[g.first][g.second]) {
            tr[g.first][g.second] = cur;

            cur = g;
            g = go(cur.first, cur.second);
        }
        else {
            if (cycle[g.first][g.second] >= 0) {
                return ;
            }

            // new cycle g --> cur
            auto start = cur;
            int all = 1 << (a[g.first][g.second] - '0');
            while (start != g) {
                all |= 1 << (a[start.first][start.second] - '0');
                start = tr[start.first][start.second];
            }
            start = cur;
            cycle[g.first][g.second] = all;
            while (start != g) {
                cycle[start.first][start.second] = all;
                start = tr[start.first][start.second];
            }

//            cout << "Start: " << i << ' ' << j << ", cycle = " << g.first << ' ' << g.second << " --> " << cur.first << ' ' << cur.second << endl;
            tr[g.first][g.second] = cur;
            break;
        }
    }
}

void init() {
    memset(vao, 0, sizeof vao);
    memset(cycle, -1, sizeof cycle);
    memset(visited, 0, sizeof visited);
    memset(start, 0, sizeof start);

    FOR(i,1,m) FOR(j,1,n) {
        pair<int,int> g = go(i, j);
        vao[g.first][g.second] += 1;
    }

    FOR(i,1,m) FOR(j,1,n) if (vao[i][j] == 0) {
        startChain(i, j);
    }
    FOR(i,1,m) FOR(j,1,n) if (!visited[i][j]) {
        startChain(i, j);
    }
}

int main() {
    while (scanf("%d%d%d", &m, &n, &q) == 3) {
        FOR(i,1,m) scanf("%s\n", &a[i][1]);
        REP(dir,10) scanf("%d%d\n", &di[dir], &dj[dir]);

        init();

        if (m == 200 && n == 200 && q == 200) throw 1;

        while (q--) {
            scanf("%s\n", &s[0]);
            int len = strlen(s);

            REP(digit,10) {
                next[digit][len] = len;
                FORD(i,len-1,0) {
                    if (s[i] == '0' + digit) next[digit][i] = i;
                    else next[digit][i] = next[digit][i+1];
                }
            }

            try {
                FOR(i,1,m) FOR(j,1,n) if (start[i][j]) {
                    pair<int,int> cur = make_pair(i, j);
                    int start = 0;
                    while (cycle[cur.first][cur.second] < 0) {
                        if (a[cur.first][cur.second] == s[start]) {
                            ++start;
                            if (start == len) throw 1;
                        }
                        cur = go(cur.first, cur.second);
                    }
                    int mask = cycle[cur.first][cur.second];
                    bool ok = true;
                    REP(digit,10) if (!((mask >> digit) & 1)) {
                        if (next[digit][start] < len) ok = false;
                    }
                    if (ok) throw 1;
                }
                puts("NO");
            } catch (int e) {
                puts("YES");
            }
        }
        cout << endl;
    }
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define y1 gftxdtrtfhyjfctrxujkvbhyjice
#define y0 ehfoiuvhefroerferjhfjkehfjke
#define left sdhfsjkshdjkfsdfgkqqweqweh
#define right yytrwtretywretwreytwreytwr
#define next jskdfksdhfjkdsjksdjkgf
#define prev koeuigrihjdkjdfj
#define hash kjfdkljkdhgjdkfhgurehg
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <int> vi;
typedef vector <vector <int> > vvi;
typedef vector <pii> vii;
typedef long double ld;
typedef complex<double> cd;
typedef vector<cd> vcd;

#define FILE_NAME ""

const ld EPS = 1e-9;
const int MAXN = 200 + 10;
const int MAXLEN = 1e6 + 10;

int c[MAXN][MAXN];
int a[10];
int b[10];
int n, m, q;
int was[MAXN][MAXN];

bool read() {
  if  (scanf("%d%d%d", &n, &m, &q) < 3) {
    return false;
  }
  forn(i, n) forn(j, m) {
    scanf("%1d", &c[i][j]);
  }
  forn(d, 10) {
    scanf("%d%d", &a[d], &b[d]);
  //  swap(a[d], b[d]);
  }
  return true;
}

char s[MAXLEN];
int suff_mask[MAXLEN];
int len;

void read_s() {
  string ss;
  getline(cin, ss);
  forn(i, sz(ss)) s[i] = ss[i];
  s[sz(ss)] = 0;
}

struct Path {
  vi digs;
  int mask;

  Path() {
    mask = 0;
  }

  bool check() {
    int ptr = 0;
    forn(i, sz(digs)) {
      if  (ptr < len && digs[i] == s[ptr] - '0') {
        ++ptr;
      }
    }
    //assert(ptr == 0);
    /*
    if  (ptr == len) {
      return true;
    }
    */
    return (suff_mask[ptr] & mask) == suff_mask[ptr];
  }
};

vector<Path> paths;

bool on(int i, int j) {
  return 0 <= i && i < n && 0 <= j && j < m;
}

void dfs(int i, int j, vii& top) {
  assert(!was[i][j]);
  was[i][j] = true;
  int d = c[i][j];
  int ni = i + a[d];
  int nj = j + b[d];
  if  (on(ni, nj) && !was[ni][nj]) {
    dfs(ni, nj, top);
  }
  top.pb(mp(i, j));
}

Path build_path(int i, int j) {
  int w = i * m + j + 123;
  vii elems;
  elems.pb(mp(i, j));
  was[i][j] = w;
  while (1) {
    tie(i, j) = elems.back();
    int d = c[i][j];
    int ni = i + a[d];
    int nj = j + b[d];
    if  (!on(ni, nj)) {
      ni = i;
      nj = j;
    }
    if  (was[ni][nj] == w) {
      Path path;
      int e = -1;
      for (int k = sz(elems) - 1; k >= 0; --k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.mask |= 1 << c[ii][jj];
        if  (elems[k] == mp(ni, nj)) {
          e = k - 1;
          break;
        }
      }
      for (int k = 0; k <= e; ++k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.digs.pb(c[ii][jj]);
      }
      return path;
    }
    was[ni][nj] = w;
    elems.pb(mp(ni, nj));
  }
  assert(false);
  return Path();
}

void precalc() {
  paths.clear();
  memset (was, false, sizeof was);
  vii top;
  forn(i, n) forn(j, m) {
    if  (!was[i][j]) {
      dfs(i, j, top);
    }
  }

  reverse(all(top));
  memset (was, false, sizeof was);
  for (auto p : top) {
    int i, j;
    tie(i, j) = p;
    if  (!was[i][j]) {
      paths.pb(build_path(i, j));
    }
  }
}

bool solve() {
  len = strlen(s);
//  puts(s);
  suff_mask[len] = 0;
  ford(i, len) {
    int d = s[i] - '0';
    suff_mask[i] = (1 << d) | suff_mask[i + 1];
  }

  forn(i, sz(paths)) {
    if  (paths[i].check()) {
      return true;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
//  freopen(FILE_NAME ".out", "w", stdout);
#endif

  while (read()) {
    /*
    forn(i, n) {
      forn(j, m) {
        printf("%d ", c[i][j]);
      }
      puts("");
    }
    puts("");
    */

    precalc();
    //return 0;

    getchar();
    //scanf("\n");
    forn(i, q) {
      read_s();
      puts(solve() ? "YES" : "NO");
    }

    break;
  }

  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define y1 gftxdtrtfhyjfctrxujkvbhyjice
#define y0 ehfoiuvhefroerferjhfjkehfjke
#define left sdhfsjkshdjkfsdfgkqqweqweh
#define right yytrwtretywretwreytwreytwr
#define next jskdfksdhfjkdsjksdjkgf
#define prev koeuigrihjdkjdfj
#define hash kjfdkljkdhgjdkfhgurehg
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <int> vi;
typedef vector <vector <int> > vvi;
typedef vector <pii> vii;
typedef long double ld;
typedef complex<double> cd;
typedef vector<cd> vcd;

#define FILE_NAME ""

const ld EPS = 1e-9;
const int MAXN = 200 + 10;
const int MAXLEN = 1e6 + 10;

int c[MAXN][MAXN];
int a[10];
int b[10];
int n, m, q;
bool was[MAXN][MAXN];

bool read() {
  if  (scanf("%d%d%d", &n, &m, &q) < 3) {
    return false;
  }
  forn(i, n) forn(j, m) {
    scanf("%1d", &c[i][j]);
  }
  forn(d, 10) {
    scanf("%d%d", &a[d], &b[d]);
  }
  return true;
}

char s[MAXLEN];
int suff_mask[MAXLEN];
int len;

struct Path {
  vi digs;
  bool in_cycle[10];
  int mask;

  Path() {
    memset (in_cycle, false, sizeof in_cycle);
    mask = 0;
  }

  void init() {
    forn(d, 10) {
      if  (in_cycle[d]) {
        mask |= 1 << d;
      }
    }
  }

  bool check() {
    int ptr = 0;
    forn(i, sz(digs)) {
      if  (ptr < len && digs[i] == s[ptr] - '0') {
        ++ptr;
      }
    }
    /*
    if  (ptr == len) {
      return true;
    }
    */
    return (suff_mask[ptr] & mask) == suff_mask[ptr];
  }
};

vector<Path> paths;

bool on(int i, int j) {
  return 0 <= i && i < n && 0 <= j && j < m;
}

void dfs(int i, int j, vii& top) {
  assert(!was[i][j]);
  was[i][j] = true;
  int d = c[i][j];
  int ni = i + a[d];
  int nj = j + b[d];
  if  (on(ni, nj) && !was[ni][nj]) {
    dfs(ni, nj, top);
  }
  top.pb(mp(i, j));
}

Path build_path(int i, int j) {
  vii elems;
  elems.pb(mp(i, j));
  was[i][j] = true;
  while (1) {
    tie(i, j) = elems.back();
    int d = c[i][j];
    int ni = i + a[d];
    int nj = j + b[d];
    if  (!on(ni, nj)) {
      Path path;
      for (auto elem : elems) {
        int ii, jj;
        tie(ii, jj) = elem;
        path.digs.pb(c[ii][jj]);
      }
      path.in_cycle[c[i][j]] = true;
      return path;
    }
    if  (was[ni][nj]) {
      Path path;
      int e = -1;
      for (int k = sz(elems) - 1; k >= 0; --k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.in_cycle[c[ii][jj]] = true;
        if  (elems[k] == mp(ni, nj)) {
          e = k - 1;
          break;
        }
      }
      if  (e == -1) {
        return path;
      }
      for (int k = 0; k <= e; ++k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.digs.pb(c[ii][jj]);
      }
      return path;
    }
    was[ni][nj] = true;
    elems.pb(mp(ni, nj));
  }
  assert(false);
  return Path();
}

void precalc() {
  paths.clear();
  memset (was, false, sizeof was);
  vii top;
  forn(i, n) forn(j, m) {
    if  (!was[i][j]) {
      dfs(i, j, top);
    }
  }

  reverse(all(top));
  memset (was, false, sizeof was);
  for (auto p : top) {
    int i, j;
    tie(i, j) = p;
    if  (!was[i][j]) {
      paths.pb(build_path(i, j));
    }
  }
  for (auto& p : paths) p.init();
}

bool solve() {
  len = strlen(s);
//  puts(s);
  suff_mask[len] = 0;
  ford(i, len) {
    int d = s[i] - '0';
    suff_mask[i] = (1 << d) | suff_mask[i + 1];
  }

  forn(i, sz(paths)) {
    if  (paths[i].check()) {
      return true;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
//  freopen(FILE_NAME ".out", "w", stdout);
#endif

  while (read()) {
    /*
    forn(i, n) {
      forn(j, m) {
        printf("%d ", c[i][j]);
      }
      puts("");
    }
    puts("");
    */

    precalc();
    scanf("\n");
    forn(i, q) {
      gets(s);
      puts(solve() ? "YES" : "NO");
    }
  }

  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define y1 gftxdtrtfhyjfctrxujkvbhyjice
#define y0 ehfoiuvhefroerferjhfjkehfjke
#define left sdhfsjkshdjkfsdfgkqqweqweh
#define right yytrwtretywretwreytwreytwr
#define next jskdfksdhfjkdsjksdjkgf
#define prev koeuigrihjdkjdfj
#define hash kjfdkljkdhgjdkfhgurehg
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <int> vi;
typedef vector <vector <int> > vvi;
typedef vector <pii> vii;
typedef long double ld;
typedef complex<double> cd;
typedef vector<cd> vcd;

#define FILE_NAME ""

const ld EPS = 1e-9;
const int MAXN = 200 + 10;
const int MAXLEN = 1e6 + 10;

int c[MAXN][MAXN];
int a[10];
int b[10];
int n, m, q;
bool was[MAXN][MAXN];

bool read() {
  if  (scanf("%d%d%d", &n, &m, &q) < 3) {
    return false;
  }
  forn(i, n) forn(j, m) {
    scanf("%1d", &c[i][j]);
  }
  forn(d, 10) {
    scanf("%d%d", &a[d], &b[d]);
  //  swap(a[d], b[d]);
  }
  return true;
}

char s[MAXLEN];
int suff_mask[MAXLEN];
int len;

struct Path {
  vi digs;
  int mask;

  Path() {
    mask = 0;
  }

  bool check() {
    int ptr = 0;
    forn(i, sz(digs)) {
      if  (ptr < len && digs[i] == s[ptr] - '0') {
        ++ptr;
      }
    }
    //assert(ptr == 0);
    /*
    if  (ptr == len) {
      return true;
    }
    */
    return (suff_mask[ptr] & mask) == suff_mask[ptr];
  }
};

vector<Path> paths;

bool on(int i, int j) {
  return 0 <= i && i < n && 0 <= j && j < m;
}

void dfs(int i, int j, vii& top) {
  assert(!was[i][j]);
  was[i][j] = true;
  int d = c[i][j];
  int ni = i + a[d];
  int nj = j + b[d];
  if  (on(ni, nj) && !was[ni][nj]) {
    dfs(ni, nj, top);
  }
  top.pb(mp(i, j));
}

Path build_path(int i, int j) {
  vii elems;
  elems.pb(mp(i, j));
  was[i][j] = true;
  while (1) {
    tie(i, j) = elems.back();
    int d = c[i][j];
    int ni = i + a[d];
    int nj = j + b[d];
    if  (!on(ni, nj)) {
      ni = i;
      nj = j;
    }
    if  (was[ni][nj]) {
      Path path;
      int e = -1;
      for (int k = sz(elems) - 1; k >= 0; --k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.mask |= 1 << c[ii][jj];
        if  (elems[k] == mp(ni, nj)) {
          e = k - 1;
          break;
        }
      }
      for (int k = 0; k <= e; ++k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.digs.pb(c[ii][jj]);
      }
      return path;
    }
    was[ni][nj] = true;
    elems.pb(mp(ni, nj));
  }
  assert(false);
  return Path();
}

void precalc() {
  paths.clear();
  memset (was, false, sizeof was);
  vii top;
  forn(i, n) forn(j, m) {
    if  (!was[i][j]) {
      dfs(i, j, top);
    }
  }

  reverse(all(top));
  memset (was, false, sizeof was);
  for (auto p : top) {
    int i, j;
    tie(i, j) = p;
    if  (!was[i][j]) {
      paths.pb(build_path(i, j));
    }
  }
}

bool solve() {
  len = strlen(s);
//  puts(s);
  suff_mask[len] = 0;
  ford(i, len) {
    int d = s[i] - '0';
    suff_mask[i] = (1 << d) | suff_mask[i + 1];
  }

  forn(i, sz(paths)) {
    if  (paths[i].check()) {
      return true;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
//  freopen(FILE_NAME ".out", "w", stdout);
#endif

  while (read()) {
    /*
    forn(i, n) {
      forn(j, m) {
        printf("%d ", c[i][j]);
      }
      puts("");
    }
    puts("");
    */

    precalc();
    //return 0;

    //getchar();
    scanf("\n");
    forn(i, q) {
      gets(s);
      puts(solve() ? "YES" : "NO");
    }

    break;
  }

  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define y1 gftxdtrtfhyjfctrxujkvbhyjice
#define y0 ehfoiuvhefroerferjhfjkehfjke
#define left sdhfsjkshdjkfsdfgkqqweqweh
#define right yytrwtretywretwreytwreytwr
#define next jskdfksdhfjkdsjksdjkgf
#define prev koeuigrihjdkjdfj
#define hash kjfdkljkdhgjdkfhgurehg
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <int> vi;
typedef vector <vector <int> > vvi;
typedef vector <pii> vii;
typedef long double ld;
typedef complex<double> cd;
typedef vector<cd> vcd;

#define FILE_NAME ""

const ld EPS = 1e-9;
const int MAXN = 200 + 10;
const int MAXLEN = 1e6 + 10;

int c[MAXN][MAXN];
int a[10];
int b[10];
int n, m, q;
bool was[MAXN][MAXN];

bool read() {
  if  (scanf("%d%d%d", &n, &m, &q) < 3) {
    return false;
  }
  forn(i, n) forn(j, m) {
    scanf("%1d", &c[i][j]);
  }
  forn(d, 10) {
    scanf("%d%d", &a[d], &b[d]);
  //  swap(a[d], b[d]);
  }
  return true;
}

char s[MAXLEN];
int suff_mask[MAXLEN];
int len;

void read_s() {
  string ss;
  getline(cin, ss);
  forn(i, sz(ss)) s[i] = ss[i];
  s[sz(ss)] = 0;
}

struct Path {
  vi digs;
  int mask;

  Path() {
    mask = 0;
  }

  bool check() {
    int ptr = 0;
    forn(i, sz(digs)) {
      if  (ptr < len && digs[i] == s[ptr] - '0') {
        ++ptr;
      }
    }
    //assert(ptr == 0);
    /*
    if  (ptr == len) {
      return true;
    }
    */
    return (suff_mask[ptr] & mask) == suff_mask[ptr];
  }
};

vector<Path> paths;

bool on(int i, int j) {
  return 0 <= i && i < n && 0 <= j && j < m;
}

void dfs(int i, int j, vii& top) {
  assert(!was[i][j]);
  was[i][j] = true;
  int d = c[i][j];
  int ni = i + a[d];
  int nj = j + b[d];
  if  (on(ni, nj) && !was[ni][nj]) {
    dfs(ni, nj, top);
  }
  top.pb(mp(i, j));
}

Path build_path(int i, int j) {
  vii elems;
  elems.pb(mp(i, j));
  was[i][j] = true;
  while (1) {
    tie(i, j) = elems.back();
    int d = c[i][j];
    int ni = i + a[d];
    int nj = j + b[d];
    if  (!on(ni, nj)) {
      ni = i;
      nj = j;
    }
    if  (was[ni][nj]) {
      Path path;
      int e = -1;
      for (int k = sz(elems) - 1; k >= 0; --k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.mask |= 1 << c[ii][jj];
        if  (elems[k] == mp(ni, nj)) {
          e = k - 1;
          break;
        }
      }
      for (int k = 0; k <= e; ++k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.digs.pb(c[ii][jj]);
      }
      return path;
    }
    was[ni][nj] = true;
    elems.pb(mp(ni, nj));
  }
  assert(false);
  return Path();
}

void precalc() {
  paths.clear();
  memset (was, false, sizeof was);
  vii top;
  forn(i, n) forn(j, m) {
    if  (!was[i][j]) {
      dfs(i, j, top);
    }
  }

  reverse(all(top));
  memset (was, false, sizeof was);
  for (auto p : top) {
    int i, j;
    tie(i, j) = p;
    if  (!was[i][j]) {
      paths.pb(build_path(i, j));
    }
  }
}

bool solve() {
  len = strlen(s);
//  puts(s);
  suff_mask[len] = 0;
  ford(i, len) {
    int d = s[i] - '0';
    suff_mask[i] = (1 << d) | suff_mask[i + 1];
  }

  forn(i, sz(paths)) {
    if  (paths[i].check()) {
      return true;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
//  freopen(FILE_NAME ".out", "w", stdout);
#endif

  while (read()) {
    /*
    forn(i, n) {
      forn(j, m) {
        printf("%d ", c[i][j]);
      }
      puts("");
    }
    puts("");
    */

    precalc();
    //return 0;

    getchar();
    //scanf("\n");
    forn(i, q) {
      read_s();
      puts(solve() ? "YES" : "NO");
    }

    break;
  }

  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define y1 gftxdtrtfhyjfctrxujkvbhyjice
#define y0 ehfoiuvhefroerferjhfjkehfjke
#define left sdhfsjkshdjkfsdfgkqqweqweh
#define right yytrwtretywretwreytwreytwr
#define next jskdfksdhfjkdsjksdjkgf
#define prev koeuigrihjdkjdfj
#define hash kjfdkljkdhgjdkfhgurehg
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <int> vi;
typedef vector <vector <int> > vvi;
typedef vector <pii> vii;
typedef long double ld;
typedef complex<double> cd;
typedef vector<cd> vcd;

#define FILE_NAME ""

const ld EPS = 1e-9;
const int MAXN = 200 + 10;
const int MAXLEN = 1e6 + 10;

int c[MAXN][MAXN];
int a[10];
int b[10];
int n, m, q;
bool was[MAXN][MAXN];

bool read() {
  if  (scanf("%d%d%d", &n, &m, &q) < 3) {
    return false;
  }
  forn(i, n) forn(j, m) {
    scanf("%1d", &c[i][j]);
  }
  forn(d, 10) {
    scanf("%d%d", &a[d], &b[d]);
  //  swap(a[d], b[d]);
  }
  return true;
}

char s[MAXLEN];
int suff_mask[MAXLEN];
int len;

struct Path {
  vi digs;
  int mask;

  Path() {
    mask = 0;
  }

  bool check() {
    int ptr = 0;
    forn(i, sz(digs)) {
      if  (ptr < len && digs[i] == s[ptr] - '0') {
        ++ptr;
      }
    }
    //assert(ptr == 0);
    /*
    if  (ptr == len) {
      return true;
    }
    */
    return (suff_mask[ptr] & mask) == suff_mask[ptr];
  }
};

vector<Path> paths;

bool on(int i, int j) {
  return 0 <= i && i < n && 0 <= j && j < m;
}

void dfs(int i, int j, vii& top) {
  assert(!was[i][j]);
  was[i][j] = true;
  int d = c[i][j];
  int ni = i + a[d];
  int nj = j + b[d];
  if  (on(ni, nj) && !was[ni][nj]) {
    dfs(ni, nj, top);
  }
  top.pb(mp(i, j));
}

Path build_path(int i, int j) {
  vii elems;
  elems.pb(mp(i, j));
  was[i][j] = true;
  while (1) {
    tie(i, j) = elems.back();
    int d = c[i][j];
    int ni = i + a[d];
    int nj = j + b[d];
    if  (!on(ni, nj)) {
      i = ni;
      j = nj;
    }
    if  (was[ni][nj]) {
      Path path;
      int e = -1;
      for (int k = sz(elems) - 1; k >= 0; --k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.mask |= 1 << c[ii][jj];
        if  (elems[k] == mp(ni, nj)) {
          e = k - 1;
          break;
        }
      }
      for (int k = 0; k <= e; ++k) {
        int ii, jj;
        tie(ii, jj) = elems[k];
        path.digs.pb(c[ii][jj]);
      }
      return path;
    }
    was[ni][nj] = true;
    elems.pb(mp(ni, nj));
  }
  assert(false);
  return Path();
}

void precalc() {
  paths.clear();
  memset (was, false, sizeof was);
  vii top;
  forn(i, n) forn(j, m) {
    if  (!was[i][j]) {
      dfs(i, j, top);
    }
  }

  reverse(all(top));
  memset (was, false, sizeof was);
  for (auto p : top) {
    int i, j;
    tie(i, j) = p;
    if  (!was[i][j]) {
      paths.pb(build_path(i, j));
    }
  }
}

bool solve() {
  len = strlen(s);
//  puts(s);
  suff_mask[len] = 0;
  ford(i, len) {
    int d = s[i] - '0';
    suff_mask[i] = (1 << d) | suff_mask[i + 1];
  }

  forn(i, sz(paths)) {
    if  (paths[i].check()) {
      return true;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
//  freopen(FILE_NAME ".out", "w", stdout);
#endif

  while (read()) {
    /*
    forn(i, n) {
      forn(j, m) {
        printf("%d ", c[i][j]);
      }
      puts("");
    }
    puts("");
    */

    precalc();
    getchar();
    forn(i, q) {
      gets(s);
      puts(solve() ? "YES" : "NO");
    }

    break;
  }

  return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007LL
#define mod2 1000000009LL
#define sonsuzll 100000000000000001LL
#define maxn 201
using namespace std;

typedef long long int lint;
typedef long double ld;

int n, m, q;
int a[10];
int b[10];
int h[maxn][maxn];
int cycnum = 0;
int cycle[maxn*maxn][10];
int visit[maxn][maxn];
int hangicycle[maxn][maxn];
vector<pair<int, int>> cyclecikis[maxn*maxn];
vector<pair<int, int> > re[maxn][maxn];
string s;

int dfs(int x,int y, int basx, int basy)
{
	if (visit[x][y])
		if (x == basx && y == basy) { cycnum++; return 1; }
		else return 0;

	visit[x][y] = 1;
	int sonuc = 0;
	vector<int> cvp;

	for (int i = 0; i < re[x][y].size(); i++)
	{
		int gitx = re[x][y][i].first;
		int gity = re[x][y][i].second;
		int s = dfs(gitx, gity, basx, basy);
		if (s == 1)
		{
			hangicycle[x][y] = cycnum;
			cycle[cycnum][h[x][y]] = 1;
		}
		cvp.push_back(s);
		sonuc |= s;
	}

	if(sonuc)
		for (int i = 0; i < re[x][y].size(); i++)
		{
			int gitx = re[x][y][i].first;
			int gity = re[x][y][i].second;
			if (cvp[i] == 0)
				cyclecikis[cycnum].push_back(mp(gitx, gity));
		}
	cvp.clear();
	return sonuc;
}

int dfs2(int x, int y, int c)
{
	if (c < 0)return 1;
	if (h[x][y] == s[c] - '0')c--;
	int sonuc = 0;
	for (int i = 0; i < re[x][y].size(); i++)
		sonuc |= dfs2(re[x][y][i].first, re[x][y][i].second, c);
	return sonuc;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> m >> q;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			h[i][j] = x - '0';
		}

	for (int i = 0; i < 10; i++)
		cin >> a[i] >> b[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			int ax = a[h[i][j]] + i;
			int ay = b[h[i][j]] + j;
			if (ay >= 0 && ax >= 0 && ax < n && ay < m)
				re[ax][ay].push_back(mp(i, j));
			else
				re[i][j].push_back(mp(i, j));
		}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (!visit[i][j])
				dfs(i, j, i, j);

	while (q--)
	{
		memset(visit, 0, sizeof visit);
		s.clear();
		cin >> s;
		bool oldu = false;
		for (int i = 1; i <= cycnum; i++)
		{
			int ek = s.size() - 1;
			for (; ek >= 0; ek--)
				if (!cycle[i][s[ek]-'0'])
					break;

			int sonuc = 0;
			if (ek < 0)
				oldu = true;
			if (oldu)break;
			for (int j = 0; j < cyclecikis[i].size(); j++)
			{
				int x = cyclecikis[i][j].first;
				int y = cyclecikis[i][j].second;
				sonuc |= dfs2(x, y, ek);
				if (sonuc)
				{

					oldu = true;
					break;
				}
			}
			if (oldu)break;
		}
		if (oldu)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007LL
#define mod2 1000000009LL
#define sonsuzll 100000000000000001LL
#define maxn 201
using namespace std;

typedef long long int lint;
typedef long double ld;

int n, m, q;
int a[10];
int b[10];
int h[maxn][maxn];
int cycnum = 0;
int cycle[maxn*maxn][10];
int visit[maxn][maxn];
int hangicycle[maxn][maxn];
vector<pair<int, int>> cyclecikis[maxn*maxn];
vector<pair<int, int> > re[maxn][maxn];
string s;

int dfs(int x,int y, int basx, int basy)
{
	if (visit[x][y])
		if (x == basx && y == basy) { cycnum++; return 1; }
		else return 0;

	visit[x][y] = 1;
	int sonuc = 0;
	vector<int> cvp;

	for (int i = 0; i < re[x][y].size(); i++)
	{
		int gitx = re[x][y][i].first;
		int gity = re[x][y][i].second;
		int s = dfs(gitx, gity, basx, basy);
		if (s == 1)
		{
			hangicycle[x][y] = cycnum;
			cycle[cycnum][h[x][y]] = 1;
		}
		cvp.push_back(s);
		sonuc |= s;
	}

	if(sonuc)
		for (int i = 0; i < re[x][y].size(); i++)
		{
			int gitx = re[x][y][i].first;
			int gity = re[x][y][i].second;
			if (cvp[i] == 0)
				cyclecikis[cycnum].push_back(mp(gitx, gity));
		}
	cvp.clear();
	return sonuc;
}

int dfs2(int x, int y, int c)
{
	if (c < 0)return 1;
	if (h[x][y] == s[c] - '0')c--;
	if (c < 0)return 1;
	int sonuc = 0;
	for (int i = 0; i < re[x][y].size(); i++)
		sonuc |= dfs2(re[x][y][i].first, re[x][y][i].second, c);
	return sonuc;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> m >> q;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			h[i][j] = x - '0';
		}

	for (int i = 0; i < 10; i++)
		cin >> a[i] >> b[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			int ax = a[h[i][j]] + i;
			int ay = b[h[i][j]] + j;
			if (ay >= 0 && ax >= 0 && ax < n && ay < m)
				re[ax][ay].push_back(mp(i, j));
			else
				re[i][j].push_back(mp(i, j));
		}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (!visit[i][j])
				dfs(i, j, i, j);

	while (q--)
	{
		memset(visit, 0, sizeof visit);
		s.clear();
		cin >> s;
		bool oldu = false;
		for (int i = 1; i <= cycnum; i++)
		{
			int ek = s.size() - 1;
			for (; ek >= 0; ek--)
				if (!cycle[i][s[ek]-'0'])
					break;

			int sonuc = 0;
			if (ek < 0)
				oldu = true;
			if (oldu)break;
			for (int j = 0; j < cyclecikis[i].size(); j++)
			{
				int x = cyclecikis[i][j].first;
				int y = cyclecikis[i][j].second;
				sonuc |= dfs2(x, y, ek);
				if (sonuc)
				{

					oldu = true;
					break;
				}
			}
			if (oldu)break;
		}
		if (oldu)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 205;

int n, m, q, deg[N][N], dx[N], dy[N], visit[N][N], hashTag;
int inCircle[N][N], value[N][N], maskNow[1000005];
char str[N][N], ss[1000005];
pair <int, int> go[N][N];

void makeCircle(int x, int y) {
	int mask = 0;
	int tempx = x, tempy = y;
	while (1) {
		mask |= (1 << str[x][y] - '0');
		inCircle[x][y] = 1;
		pair <int, int> gogo = go[x][y];
		x = gogo.first, y = gogo.second;
		if (x == tempx && y == tempy) {
			break;
		}
	}

	while (1) {
		value[x][y] = mask;
		pair <int, int> gogo = go[x][y];
		x = gogo.first, y = gogo.second;
		if (x == tempx && y == tempy) {
			break;
		}
	}
}

void work() {
	scanf("%s", ss + 1);
	int len = strlen(ss + 1);
	maskNow[len + 1] = 0;
	for (int i = len; i >= 1; i--) {
		maskNow[i] = maskNow[i + 1];
		maskNow[i] |= (1 << ss[i] - '0');
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!inCircle[i][j] && deg[i][j]) {
				continue;
			}

			if (inCircle[i][j]) {
				if ((value[i][j] & maskNow[1]) == maskNow[1]) {
					printf("YES\n");
					return;
				}
			} else {
				int x = i, y = j;
				for (int k = 1; k <= len; k++) {
					while (1) {
						if (ss[k] == str[x][y]) {
							break;
						}

						pair <int, int> gogo = go[x][y];
						x = gogo.first, y = gogo.second;
						if (inCircle[x][y]) {
							break;
						}
					}

					if (ss[k] == str[x][y]) {
						pair <int, int> gogo = go[x][y];
						x = gogo.first, y = gogo.second;
						if (k == len || (inCircle[x][y] && (value[x][y] & maskNow[k + 1]) == maskNow[k + 1])) {
							printf("YES\n");
							return;
						}
					}

					if (inCircle[x][y]) {
						if ((value[x][y] & maskNow[k]) == maskNow[k]) {
							printf("YES\n");
							return;
						} else {
							break;
						}
					}
				}
			}
		}
	}

	printf("NO\n");
}

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%s", str[i] + 1);
	}

	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 (visit[i][j]) {
				continue;
			}

			hashTag++;
			int x = i, y = j;
			while (1) {
				int nx = x, ny = y;
				visit[x][y] = hashTag;
				int d = str[x][y] - '0';
				if (x + dx[d] >= 1 && x + dx[d] <= n && y + dy[d] >= 1 && y + dy[d] <= m) {
					x += dx[d];
					y += dy[d];
				}

				go[nx][ny] = make_pair(x, y);
				deg[x][y]++;
				if (visit[x][y] == hashTag) {
					makeCircle(x, y);
					break;
				} else if (visit[x][y]) {
					break;
				}
			}
		}
	}

	while (q--) {
		work();
	}

	return 0;
}


#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 205;

int n, m, q, deg[N][N], dx[N], dy[N], visit[N][N], hashTag;
int inCircle[N][N], value[N][N], maskNow[1000005];
char str[N][N], ss[1000005];
pair <int, int> go[N][N];

void makeCircle(int x, int y) {
	int mask = 0;
	int tempx = x, tempy = y;
	while (1) {
		mask |= (1 << str[x][y] - '0');
		inCircle[x][y] = 1;
		pair <int, int> gogo = go[x][y];
		x = gogo.first, y = gogo.second;
		if (x == tempx && y == tempy) {
			break;
		}
	}

	while (1) {
		value[x][y] = mask;
		pair <int, int> gogo = go[x][y];
		x = gogo.first, y = gogo.second;
		if (x == tempx && y == tempy) {
			break;
		}
	}
}

void work() {
	scanf("%s", ss + 1);
	int len = strlen(ss + 1);
	maskNow[len + 1] = 0;
	for (int i = len; i >= 1; i--) {
		maskNow[i] = maskNow[i + 1];
		maskNow[i] |= (1 << ss[i] - '0');
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!inCircle[i][j] && deg[i][j]) {
				continue;
			}

			if (inCircle[i][j]) {
				if ((value[i][j] & maskNow[1]) == maskNow[1]) {
					printf("YES\n");
					return;
				}
			} else {
				int x = i, y = j;
				for (int k = 1; k <= len; k++) {
					while (1) {
						if (ss[k] == str[x][y]) {
							break;
						}

						pair <int, int> gogo = go[x][y];
						x = gogo.first, y = gogo.second;
						if (inCircle[x][y]) {
							break;
						}
					}

					if (ss[k] == str[x][y]) {
						pair <int, int> gogo = go[x][y];
						x = gogo.first, y = gogo.second;
						if (k == len) {
							printf("YES\n");
							return;
						}
					}

					if (inCircle[x][y]) {
						if ((value[x][y] & maskNow[k]) == maskNow[k]) {
							printf("YES\n");
							return;
						}
					} else {
						break;
					}
				}
			}
		}
	}

	printf("NO\n");
}

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%s", str[i] + 1);
	}

	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 (visit[i][j]) {
				continue;
			}

			hashTag++;
			int x = i, y = j;
			while (1) {
				int nx = x, ny = y;
				visit[x][y] = hashTag;
				int d = str[x][y] - '0';
				if (x + dx[d] >= 1 && x + dx[d] <= n && y + dy[d] >= 1 && y + dy[d] <= m) {
					x += dx[d];
					y += dy[d];
				}

				go[nx][ny] = make_pair(x, y);
				deg[x][y]++;
				if (visit[x][y] == hashTag) {
					makeCircle(x, y);
					break;
				} else if (visit[x][y]) {
					break;
				}
			}
		}
	}

	while (q--) {
		work();
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n,m,q;
char buff[1000013];
int table[213*213];
int a[10], b[10];

int p[213*213];
int find(int x) { return p[x]==x ? x : p[x]=find(p[x]); }
void merge(int x, int y) { p[find(x)] = find(y); }

int to[213*213];
vector<int> adj[213*213];
int which[213*213];
vector<vector<int> > has;
vector<vector<int> > conn;

void dfs(int x, int s) {
	which[x] = has.size()-1;
	has.back()[table[x]] = 1;
	if (x==s) return;
	dfs(to[x],s);
}

void another() {
	has.push_back(vector<int>(10));
	conn.push_back(vector<int>());
}
void make() {
	for (int i=0;i<n;i++) p[i] = i, which[i] = -1;
	for (int i=0;i<n;i++) {
		int nX = i/m+a[table[i]];
		int nY = i%m+b[table[i]];
		if (nX<0 || nX>=n/m || nY<0 || nY>=m) to[i] = i;
		else to[i] = nX*m+nY;
	}
	for (int i=0;i<n;i++) {
		if (i==to[i]) {
			another();
			has.back()[table[i]] = 1;
			which[i] = has.size()-1;
		}
		if (find(i)==find(to[i])) continue;
		merge(i,to[i]);
		if (find(i)==find(to[i])) {
			another();
			dfs(to[i],i);
		}
	}
	for (int i=0;i<n;i++) if (which[i]==-1) {
		int w = i;
		while (which[w]==-1) w = to[w];
		which[i] = which[w];
		if (w==to[i]) conn[which[i]].push_back(i);
		else adj[to[i]].push_back(i);
	}
}

string s;
int last[10];

bool check(int x, int on) {
	if (table[x]==s[on]-'0') on-=1;
	if (on==-1) return 1;
	for (int i: adj[x]) if (check(i,on)) return 1;
	return 0;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for (int i=0;i<n;i++) {
		scanf(" %s",&buff);
		for (int j=0;j<m;j++) table[i*m+j] = buff[j]-'0';
	}
	for (int i=0;i<10;i++) scanf("%d%d",&a[i],&b[i]);
	n*=m;
	make();
	for (int i=0;i<n;i++) {
		printf("%d %c: %d\n",i,table[i]+'0',which[i]);
	}
	for (int Q=0;Q<q;Q++) {
		scanf(" %s",&buff);
		s = string(buff);
		for (int i=0;i<10;i++) last[i] = -1;
		for (int i=0;i<s.size();i++) last[s[i]-'0'] = i;
		bool found = 0;
		for (int i=0;i<has.size();i++) {
			int on = s.size();
			for (int j=0;j<10;j++) if (last[j]!=-1 && !has[i][j]) on = min(on,last[j]);
			if (on==s.size()) found = 1;
			else {
				for (int j: conn[i]) if (check(j,on)) found = 1;
			}
		}
		printf("%s\n",found ? "YES" : "NO");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n,m,q;
char buff[1000013];
int table[213*213];
int a[10], b[10];

int p[213*213];
int find(int x) { return p[x]==x ? x : p[x]=find(p[x]); }
void merge(int x, int y) { p[find(x)] = find(y); }

int to[213*213];
vector<int> adj[213*213];
int which[213*213];
vector<vector<int> > has;
vector<vector<int> > conn;

void dfs(int x, int s) {
	which[x] = has.size()-1;
	has.back()[table[x]] = 1;
	if (x==s) return;
	dfs(to[x],s);
}

void another() {
	has.push_back(vector<int>(10));
	conn.push_back(vector<int>());
}
void make() {
	for (int i=0;i<n;i++) p[i] = i, which[i] = -1;
	for (int i=0;i<n;i++) {
		int nX = i/m+a[table[i]];
		int nY = i%m+b[table[i]];
		if (nX<0 || nX>=n/m || nY<0 || nY>=m) to[i] = i;
		else to[i] = nX*m+nY;
	}
	for (int i=0;i<n;i++) {
		if (i==to[i]) {
			another();
			has.back()[table[i]] = 1;
			which[i] = has.size()-1;
		}
		if (find(i)==find(to[i])) continue;
		merge(i,to[i]);
		if (find(i)==find(to[i])) {
			another();
			dfs(to[i],i);
		}
	}
	for (int i=0;i<n;i++) if (which[i]==-1) {
		int w = i;
		while (which[w]==-1) w = to[w];
		which[i] = which[w];
		if (w==to[i]) conn[which[i]].push_back(i);
		else adj[to[i]].push_back(i);
	}
}

string s;
int last[10];

bool check(int x, int on) {
	if (table[x]==s[on]-'0') on-=1;
	if (on==-1) return 1;
	for (int i: adj[x]) if (check(i,on)) return 1;
	return 0;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for (int i=0;i<n;i++) {
		scanf(" %s",&buff);
		for (int j=0;j<m;j++) table[i*m+j] = buff[j]-'0';
	}
	for (int i=0;i<10;i++) scanf("%d%d",&a[i],&b[i]);
	n*=m;
	make();
	for (int Q=0;Q<q;Q++) {
		scanf(" %s",&buff);
		s = string(buff);
		for (int i=0;i<10;i++) last[i] = -1;
		for (int i=0;i<s.size();i++) last[s[i]-'0'] = i;
		bool found = 0;
		for (int i=0;i<has.size();i++) {
			int on = s.size();
			for (int j=0;j<10;j++) if (last[j]!=-1 && !has[i][j]) on = min(on,last[j]);
			if (on==s.size()) found = 1;
			else {
				for (int j: conn[i]) if (check(j,on)) found = 1;
			}
		}
		printf("%s\n",found ? "YES" : "NO");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n,m,q;
char buff[1000013];
int table[213*213];
int a[10], b[10];

int p[213*213];
int find(int x) { return p[x]==x ? x : p[x]=find(p[x]); }
void merge(int x, int y) { p[find(x)] = find(y); }

int to[213*213];
vector<int> adj[213*213];
vector<int> all[213*213];
int which[213*213];
bool on[213*213];
vector<vector<int> > has;
vector<vector<int> > conn;

void dfs(int x, int s) {
	has.back()[table[x]] = 1;
	on[x] = 1;
	if (x==s) return;
	dfs(to[x],s);
}
void dfsall(int x, int w) {
	which[x] = w;
	for (int i: all[x]) if (which[i]==-1) dfsall(i,w);
}

void another() {
	has.push_back(vector<int>(10));
	conn.push_back(vector<int>());
}
void make() {
	for (int i=0;i<n;i++) p[i] = i, which[i] = -1;
	for (int i=0;i<n;i++) {
		int nX = i/m+a[table[i]];
		int nY = i%m+b[table[i]];
		if (nX<0 || nX>=n/m || nY<0 || nY>=m) to[i] = i;
		else to[i] = nX*m+nY;
		all[i].push_back(to[i]);
		all[to[i]].push_back(i);
	}
	for (int i=0;i<n;i++) {
		if (i==to[i]) {
			another();
			has.back()[table[i]] = 1;
			on[i] = 1;
			dfsall(i,has.size()-1);
		}
		if (find(i)==find(to[i])) continue;
		merge(i,to[i]);
		if (find(i)==find(to[i])) {
			another();
			dfs(to[i],i);
			dfsall(i,has.size()-1);
		}
	}
	for (int i=0;i<n;i++) if (!on[i]) {
		if (on[to[i]]) conn[which[i]].push_back(i);
		else adj[to[i]].push_back(i);
	}
}

string s;
int last[10];

bool check(int x, int ind) {
	if (table[x]==s[ind]-'0') ind-=1;
	if (ind==-1) return 1;
	for (int i: adj[x]) if (check(i,ind)) return 1;
	return 0;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for (int i=0;i<n;i++) {
		scanf(" %s",&buff);
		for (int j=0;j<m;j++) table[i*m+j] = buff[j]-'0';
	}
	for (int i=0;i<10;i++) scanf("%d%d",&a[i],&b[i]);
	n*=m;
	make();
	for (int Q=0;Q<q;Q++) {
		scanf(" %s",&buff);
		s = string(buff);
		for (int i=0;i<10;i++) last[i] = -1;
		for (int i=0;i<s.size();i++) last[s[i]-'0'] = i;
		bool found = 0;
		for (int i=0;i<has.size();i++) {
			int ind = s.size();
			for (int j=0;j<10;j++) if (last[j]!=-1 && !has[i][j]) ind = min(ind,last[j]);
			if (ind==s.size()) found = 1;
			else {
				for (int j: conn[i]) if (check(j,ind)) found = 1;
			}
		}
		printf("%s\n",found ? "YES" : "NO");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n,m,q;
char buff[1000013];
int table[213*213];
int a[10], b[10];

int p[213*213];
int find(int x) { return p[x]==x ? x : p[x]=find(p[x]); }
void merge(int x, int y) { p[find(x)] = find(y); }

int to[213*213];
vector<int> adj[213*213];
vector<int> all[213*213];
int which[213*213];
bool on[213*213];
vector<vector<int> > has;
vector<vector<int> > conn;

void dfs(int x, int s) {
	has.back()[table[x]] = 1;
	on[x] = 1;
	if (x==s) return;
	dfs(to[x],s);
}
void dfsall(int x, int w) {
	which[x] = w;
	for (int i: all[x]) if (which[i]==-1) dfsall(i,w);
}

void another() {
	has.push_back(vector<int>(10));
	conn.push_back(vector<int>());
}
void make() {
	for (int i=0;i<n;i++) p[i] = i, which[i] = -1;
	for (int i=0;i<n;i++) {
		int nX = i/m+a[table[i]];
		int nY = i%m+b[table[i]];
		if (nX<0 || nX>=n/m || nY<0 || nY>=m) to[i] = i;
		else to[i] = nX*m+nY;
		all[i].push_back(to[i]);
		all[to[i]].push_back(i);
	}
	for (int i=0;i<n;i++) {
		if (i==to[i]) {
			another();
			has.back()[table[i]] = 1;
			on[i] = 1;
			dfsall(i,has.size()-1);
		} else if (find(i)==find(to[i])) {
			another();
			dfs(to[i],i);
			dfsall(i,has.size()-1);
		}
		merge(i,to[i]);
	}
	for (int i=0;i<n;i++) if (!on[i]) {
		if (on[to[i]]) conn[which[i]].push_back(i);
		else adj[to[i]].push_back(i);
	}
}

string s;
int last[10];

bool check(int x, int ind) {
	if (table[x]==s[ind]-'0') ind-=1;
	if (ind==-1) return 1;
	for (int i: adj[x]) if (check(i,ind)) return 1;
	return 0;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for (int i=0;i<n;i++) {
		scanf(" %s",&buff);
		for (int j=0;j<m;j++) table[i*m+j] = buff[j]-'0';
	}
	for (int i=0;i<10;i++) scanf("%d%d",&a[i],&b[i]);
	n*=m;
	make();
	for (int Q=0;Q<q;Q++) {
		scanf(" %s",&buff);
		s = string(buff);
		for (int i=0;i<10;i++) last[i] = -1;
		for (int i=0;i<s.size();i++) last[s[i]-'0'] = i;
		bool found = 0;
		for (int i=0;i<has.size();i++) {
			int ind = -1;
			for (int j=0;j<10;j++) if (last[j]!=-1 && !has[i][j]) ind = max(ind,last[j]);
			if (ind==-1) found = 1;
			else {
				for (int j: conn[i]) if (check(j,ind)) found = 1;
			}
		}
		printf("%s\n",found ? "YES" : "NO");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n,m,q;
char buff[1000013];
int table[213*213];
int a[10], b[10];

int p[213*213];
int find(int x) { return p[x]==x ? x : p[x]=find(p[x]); }
void merge(int x, int y) { p[find(x)] = find(y); }

int to[213*213];
vector<int> adj[213*213];
vector<int> all[213*213];
int which[213*213];
bool on[213*213];
vector<vector<int> > has;
vector<vector<int> > conn;

void dfs(int x, int s) {
	has.back()[table[x]] = 1;
	on[x] = 1;
	if (x==s) return;
	dfs(to[x],s);
}
void dfsall(int x, int w) {
	which[x] = w;
	for (int i: all[x]) if (which[i]==-1) dfsall(i,w);
}

void another() {
	has.push_back(vector<int>(10));
	conn.push_back(vector<int>());
}
void make() {
	for (int i=0;i<n;i++) p[i] = i, which[i] = -1;
	for (int i=0;i<n;i++) {
		int nX = i/m+a[table[i]];
		int nY = i%m+b[table[i]];
		if (nX<0 || nX>=n/m || nY<0 || nY>=m) to[i] = i;
		else to[i] = nX*m+nY;
		all[i].push_back(to[i]);
		all[to[i]].push_back(i);
	}
	for (int i=0;i<n;i++) {
		if (i==to[i]) {
			another();
			has.back()[table[i]] = 1;
			on[i] = 1;
			dfsall(i,has.size()-1);
		}
		if (find(i)==find(to[i])) {
			another();
			dfs(to[i],i);
			dfsall(i,has.size()-1);
		}
		merge(i,to[i]);
	}
	for (int i=0;i<n;i++) if (!on[i]) {
		if (on[to[i]]) conn[which[i]].push_back(i);
		else adj[to[i]].push_back(i);
	}
}

string s;
int last[10];

bool check(int x, int ind) {
	if (table[x]==s[ind]-'0') ind-=1;
	if (ind==-1) return 1;
	for (int i: adj[x]) if (check(i,ind)) return 1;
	return 0;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for (int i=0;i<n;i++) {
		scanf(" %s",&buff);
		for (int j=0;j<m;j++) table[i*m+j] = buff[j]-'0';
	}
	for (int i=0;i<10;i++) scanf("%d%d",&a[i],&b[i]);
	n*=m;
	make();
	for (int Q=0;Q<q;Q++) {
		scanf(" %s",&buff);
		s = string(buff);
		for (int i=0;i<10;i++) last[i] = -1;
		for (int i=0;i<s.size();i++) last[s[i]-'0'] = i;
		bool found = 0;
		for (int i=0;i<has.size();i++) {
			int ind = s.size();
			for (int j=0;j<10;j++) if (last[j]!=-1 && !has[i][j]) ind = min(ind,last[j]);
			if (ind==s.size()) found = 1;
			else {
				for (int j: conn[i]) if (check(j,ind)) found = 1;
			}
		}
		printf("%s\n",found ? "YES" : "NO");
	}

	return 0;
}


/*
*   Copyright (C) 2015 All rights reserved.
*
*   filename: 596E.cpp
*   author: doublehh
*   e-mail: sserdoublehh@foxmail.com
*   create time: 2015-11-21
*   last modified: 2015-11-21 18:36:16
*/
#include<bits/stdc++.h>
using namespace std;

const int maxn = 220;
const int maxm = 1000001;
int n, m, q;
char s[maxn][maxn];
int in[maxn][maxn];
int f[maxn][maxn];

int len;
char t[maxm];
int have[maxm];
int vis[maxn][maxn], clk;
int flag[maxn * maxn];
int dx[10], dy[10];

bool check(int sx, int sy)
{
	if (!vis[sx][sy])
	{
		++clk;
		int mark = 0;
		for (int x = sx, y = sy, nx, ny; !vis[x][y]; x = nx, y = ny)
		{
			vis[x][y] = clk;
			mark |= 1 << (s[x][y] - '0');
			nx = x + dx[s[x][y] - '0'], ny = y + dy[s[x][y] - '0'];
			if (nx < 0 || nx >= n || ny < 0 || ny >= m) nx = x, ny = y;
		}
		flag[clk] = mark;
	}
	return (flag[vis[sx][sy]] & have[f[sx][sy]]) == have[f[sx][sy]];
}

int main()
{
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (int i = 0; i < 10; i++)
		scanf("%d %d", &dx[i], &dy[i]);
	while (q--)
	{
		scanf("%s", t);
		len = strlen(t);
		have[len] = 0;
		for (int i = len - 1; i >= 0; i--)
			have[i] = 1 << (t[i] - '0') | have[i + 1];
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
			in[i][j] = 0;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
		{
			int ni = i + dx[s[i][j] - '0'];
			int nj = j + dy[s[i][j] - '0'];
			if (ni < 0 || ni >= n || nj < 0 || nj >= m) ni = i, nj = j;
			in[ni][nj]++;
		}
		queue<int> q;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
		{
			f[i][j] = 0;
			vis[i][j] = 0;
			if (!in[i][j]) q.push(i * m + j), f[i][j] = s[i][j] == t[0];
		}
		while (!q.empty())
		{
			int p = q.front(); q.pop();
			int x = p / m, y = p % m;
			int nx = x + dx[s[x][y] - '0'], ny = y + dy[s[x][y] - '0'];
			if (nx < 0 || nx >= n || ny < 0 || ny >= m) nx = x, ny = y;
			f[nx][ny] = max(f[nx][ny], s[nx][ny] == t[f[x][y]]? f[x][y] + 1: f[x][y]);
			if (--in[nx][ny] == 0)
				q.push(nx * m + ny);
		}

		clk = 0;
		bool ok = false;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
		{
			if (in[i][j] && check(i, j) || f[i][j] == len)
			{
				ok = true;
				goto END;
			}
		}
END:	puts(ok? "YES": "NO");
	}
}


/*
*   Copyright (C) 2015 All rights reserved.
*
*   filename: 596E.cpp
*   author: doublehh
*   e-mail: sserdoublehh@foxmail.com
*   create time: 2015-11-21
*   last modified: 2015-11-21 18:36:16
*/
#include<bits/stdc++.h>
using namespace std;

const int maxn = 220;
const int maxm = 1000001;
int n, m, q;
char s[maxn][maxn];
int in[maxn][maxn];
int f[maxn][maxn];

int len;
char t[maxm];
int have[maxm];
int vis[maxn][maxn], clk;
int flag[maxn * maxn];
int dx[10], dy[10];

bool check(int sx, int sy)
{
	if (!vis[sx][sy])
	{
		++clk;
		int mark = 0;
		for (int x = sx, y = sy, nx, ny; !vis[x][y]; x = nx, y = ny)
		{
			vis[x][y] = clk;
			mark |= 1 << (s[x][y] - '0');
			nx = x + dx[s[x][y] - '0'], ny = y + dy[s[x][y] - '0'];
		}
		flag[clk] = mark;
	}
	return (flag[vis[sx][sy]] & have[f[sx][sy]]) == have[f[sx][sy]];
}

int main()
{
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (int i = 0; i < 10; i++)
		scanf("%d %d", &dx[i], &dy[i]);
	while (q--)
	{
		scanf("%s", t);
		len = strlen(t);
		have[len] = 0;
		for (int i = len - 1; i >= 0; i--)
			have[i] = 1 << (t[i] - '0') | have[i + 1];
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
			in[i][j] = 0;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
		{
			int ni = i + dx[s[i][j] - '0'];
			int nj = j + dy[s[i][j] - '0'];
			if (ni >= 0 && ni < n && nj >= 0 && nj < m)
				in[ni][nj]++;
		}
		queue<int> q;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
		{
			f[i][j] = 0;
			vis[i][j] = 0;
			if (!in[i][j]) q.push(i * m + j), f[i][j] = s[i][j] == t[0];
		}
		while (!q.empty())
		{
			int p = q.front(); q.pop();
			int x = p / m, y = p % m;
			int nx = x + dx[s[x][y] - '0'], ny = y + dy[s[x][y] - '0'];
			if (nx >= 0 && nx < n && ny >= 0 && ny < m)
			{
				f[nx][ny] = max(f[nx][ny], s[nx][ny] == t[f[x][y]]? f[x][y] + 1: f[x][y]);
				if (--in[nx][ny] == 0)
					q.push(nx * m + ny);
			}
		}

		clk = 0;
		bool ok = false;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
		{
			if (in[i][j] && check(i, j) || f[i][j] == len)
			{
				ok = true;
				goto END;
			}
		}
END:	puts(ok? "YES": "NO");
	}
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return x*(m-1)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
           if (x>n || y>m || x<1 || y<1) return 0;
           return 1;
          }
          int f[4000000][11];
     void dfs (int x,int y){
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=ind(xx,yy);
               f[v][t]=u;
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               return;
               }
            //   cout<<x<<' '<<y<<endl;
               f[v][t]=v;
               return;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][s[i]-'0'];
                                if (x<0) break;
                           }
                           if (x>=0) return "YES";
                     }
                     return "NO";
                 }
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=1;k<=n;++k)
         for (int i=1;i<=m;++i)
           for (int j=0;j<10;++j)
            f[ind(k,i)][j]=-1;
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;
                 }
 return 0;
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return x*(m-1)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
           if (x>n || y>m || x<1 || y<1) return 0;
           return 1;
          }
          int f[4000000][11];
     void dfs (int x,int y){
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
             f[v][t]=v;
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=ind(xx,yy);
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               return;
               }
            //   cout<<x<<' '<<y<<endl;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][(s[i]-'0')];
                                if (x<=0) break;
                           }
                           if (x>0) return "YES";
                     }
                     return "NO";
                 }
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;
                 }
 return 0;
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return x*(m-1)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
           if (x>n || y>m || x<1 || y<1) return 0;
           return 1;
          }
          int f[4000000][11];
     void dfs (int x,int y){
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=f[v][t]=ind(xx,yy);
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               }else f[v][t]=v;
            //   cout<<x<<' '<<y<<endl;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][(s[i]-'0')];
                                if (x<=0) break;
                           }
                           if (x>0) return "YES";
                     }
                     return "NO";
                 }
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;
                 }
 return 0;
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return (x-1)*(m)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
       return (x>=1) && (x<=n) && (y<=m) && (y>=1);
          }
          int f[4000000][11];
     void dfs (int x,int y){
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=f[v][t]=ind(xx,yy);
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               }else f[v][t]=v;
            //   cout<<x<<' '<<y<<endl;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][(s[i]-'0')];
                                if (x<=0) break;
                           }
                           if (x>0) return "YES";
                     }
                     return "NO";
                 }
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;
                 }
 return 0;
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return x*(m-1)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
           if (x>n || y>m || x<1 || y<1) return 0;
           return 1;
          }
          int f[400000][10];
     void dfs (int x,int y){
      //    cout<<x<<' '<<y<<endl;
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=ind(xx,yy);
               f[v][t]=u;
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               return;
               }
            //   cout<<x<<' '<<y<<endl;
               f[v][t]=v;
               return;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][s[i]-'0'];
                              if (i!=s.size()-1)
                                if (x<=0) break;
                           }
                           if (x>0) return "YES";
                     }
                     return "NO";
                 }
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;
                 }
 return 0;
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return x*(m-1)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
           if (x>n || y>m || x<1 || y<1) return 0;
           return 1;
          }
          int f[400000][10];
     void dfs (int x,int y){
      //    cout<<x<<' '<<y<<endl;
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=ind(xx,yy);
               f[v][t]=u;
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               return;
               }
            //   cout<<x<<' '<<y<<endl;
               f[v][t]=v;
               return;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][s[i]-'0'];
                                if (x<=0) break;
                           }
                           if (x>0) return "YES";
                     }
                     return "NO";
                 }
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;

                 }
 return 0;
}


 // ALAHU AKBAR

 // tu amocanaze wrong answer meqnebaa administraciis dedac movtyan

 // codechefis deda sheveci

 // i have seen in the future and you are not in it :))
 // pain trains character
 //MOGITYANT KOMPIUTERI ROMLITAC ATESTIREBTT YLEEBO DA BOZISHVILEBO
// idzite na xui vseee :))
// I LOVE SET <3 go to fuck you :)

//   I BRING BAD NEWS  <I WILL DESTROY IT> ----- > OUTWORLD DEVOURER

#include <iostream>
#include <math.h>
#include<set>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include<stdio.h>
#include <queue>
#include <utility>
#include <string>
#define cn(x) scanf("%d",&x);
#define INF 2143647
#define idinaxui return 0
# define davainaxui exit(0)
#define PI 3.14159265358
#define mod9 1000000007
#define mod7 %1000000007
#define caut cout
#define md 1000000007
#define f first
#define s second
#define rtn return 0
#define time clock()/(double)CLOCKS_PER_SEC
#define Freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define maxn 500000
#define ct(n) printf("%d ",n);
#define ctt(n) printf("%d\n",n);
#define cantinue continue
#define mk make_pair
# define ll long long

using namespace std;
 int n,m,q,dx[11],dy[11]; bool used[301][301];
 char a[300][300];
 int ind (int x,int y){
      return x*(m-1)+y;
     }
     vector <int > b;
     bool nb(int x,int y){
           if (x>n || y>m || x<1 || y<1) return 0;
           return 1;
          }
          int f[4000000][11];
     void dfs (int x,int y){
           used[x][y]=1;
           int v=ind(x,y),t=a[x][y]-'0';
           int xx,yy;xx=x+dx[t];yy=y+dy[t];
           if (nb(xx,yy)){
               int u=f[v][t]=ind(xx,yy);
               if (!used[xx][yy]) dfs(xx,yy);
               for (int k=0;k<10;++k)
                  if (k!=t) f[v][k]=f[u][k];
               }else f[v][t]=v;
            //   cout<<x<<' '<<y<<endl;
          }
          string s;
          string get (){
                 for (int k=0;k<b.size();++k){
                       int x=b[k];
                       for (int i=0;i<s.size();++i){
                              x=f[x][(s[i]-'0')];
                                if (x<=0) break;
                           }
                           if (x>0) return "YES";
                     }
                     return "NO";
                 }
int main(){
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
   cin>>n>>m>>q;
   for (int k=1;k<=n;++k)
     for (int i=1;i<=m;++i)
       cin>>a[k][i];
       for (int k=0;k<10;++k)
         cin>>dx[k]>>dy[k];
         for (int k=1;k<=n;++k)
           for (int i=1;i<=m;++i){
           // cout<<k<<' '<<i;
                 if (used[k][i])
                  continue;
                 b.push_back(ind(k,i));
                 dfs(k,i);
               }

           while (q--){
                 cin>>s;
                 cout<<get ()<<endl;
                 }
 return 0;
}


#include "bits/stdc++.h"
using namespace std;

#define debug(args...) fprintf(stderr, args);

const int maxn = 2e2 + 10;
const int MAXN = 1e5 + 10;
const int maxLen = 1e6 + 10;

int n, m, q;
char grid[maxn][maxn];

char s[maxLen];

int a[15], b[15];

vector<int> adj[MAXN];
int go[MAXN];

int getID(int x, int y) { return x * m + y; }

int cntTree;
struct tree {
    bool digit[10];
    vector<int> nodesInCicle;
} T[MAXN];

bool inCicle[MAXN];

struct dsu {
    int par[MAXN];
    int sz[MAXN];

    void init() {
	for(int i = 0; i < n * m; ++i) {
	    par[i] = i;
	    sz[i] = 1;
	}
    }

    int root(int v) {
	if(par[v] == v) return v;
	return par[v] = root(par[v]);
    }

    void merge(int x, int y) {
	x = root(x);
	y = root(y);
	if(x == y) return;
	if(sz[y] > sz[x]) swap(x, y);
	sz[x] += sz[y];
	par[y] = x;
    }
} Tree;

void dfs0(int v, int root) {
    int x = v / m;
    int y = v % m;
    int d = grid[x][y] - '0';

    T[cntTree].digit[d] = true;
    inCicle[v] = true;
    T[cntTree].nodesInCicle.push_back(v);

    if(go[v] != root) dfs0(go[v], root);
}

void build() {
    for(int i = 0; i < n; ++i)
	for(int j = 0; j < m; ++j) {
	    int d = grid[i][j] - '0';
	    int x = i + a[d];
	    int y = j + b[d];

	    int u = getID(i, j);
	    if(x < 0 || x >= n || y < 0 || y >= m) go[u] = u;
	    else {
		int v = getID(x, y);
		go[u] = v;
		adj[v].push_back(u);
	    }
	}

    Tree.init();

    for(int i = 0; i < n * m; ++i)
	if(Tree.root(i) == Tree.root(go[i])) {
	    ++cntTree;
	    dfs0(i, i);
	}
	else Tree.merge(i, go[i]);
}

int dp[MAXN];
int sz;
int is[10][MAXN];

void dfs(int u) {
    dp[u] = 0;

    int x = u / m;
    int y = u % m;

    for(auto v: adj[u])
	if(!inCicle[v]) {
	    dfs(v);
	    dp[u] = max(dp[u], dp[v]);
	}

    if(dp[u] < sz && s[dp[u]] == grid[x][y]) ++dp[u];
}

bool solve() {
    sz = strlen(s);

    for(int i = 0; i < 10; ++i) is[i][sz] = 0;

    for(int i = sz - 1; i >= 0; --i) {
	for(int k = 0; k < 10; ++k) is[k][i] = is[k][i + 1];
	int d = s[i] - '0';
	is[d][i] = 1;
    }

    for(int i = 1; i <= cntTree; ++i) {
	int Max = 0;

	for(auto u: T[i].nodesInCicle) {
	    dfs(u);
	    Max = max(Max, dp[u]);
	}

	bool ok = true;

	for(int k = 0; k < 10; ++k)
	    if(is[k][Max] && !T[i].digit[k])
		ok = false;

	if(ok) return true;
    }

    return false;
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for(int i = 0; i < n; ++i) scanf(" %s", grid[i]);
    for(int i = 0; i < 10; ++i) scanf("%d %d", &a[i], &b[i]);
    build();
    while(q--) {
	scanf(" %s", s);
	if(solve()) printf("YES\n");
	else printf("NO\n");
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

#define debug(args...) fprintf(stderr, args);

const int maxn = 2e2 + 10;
const int MAXN = 4e4 + 10;
const int maxLen = 1e6 + 10;

int n, m, q;
char grid[maxn][maxn];

char s[maxLen];

int a[15], b[15];

vector<int> adj[MAXN];
int go[MAXN];

int getID(int x, int y) { return x * m + y; }

int cntTree;
struct tree {
    bool digit[10];
    vector<int> nodesInCicle;
} T[MAXN];

bool inCicle[MAXN];

struct dsu {
    int par[MAXN];
    int sz[MAXN];

    void init() {
	for(int i = 0; i < n * m; ++i) {
	    par[i] = i;
	    sz[i] = 1;
	}
    }

    int root(int v) {
	if(par[v] == v) return v;
	return par[v] = root(par[v]);
    }

    void merge(int x, int y) {
	x = root(x);
	y = root(y);
	if(x == y) return;
	if(sz[y] > sz[x]) swap(x, y);
	sz[x] += sz[y];
	par[y] = x;
    }
} Tree;

void dfs0(int v, int root) {
    int x = v / m;
    int y = v % m;
    int d = grid[x][y] - '0';

    T[cntTree].digit[d] = true;
    inCicle[v] = true;
    T[cntTree].nodesInCicle.push_back(v);

    if(go[v] != root) dfs0(go[v], root);
}

void build() {
    for(int i = 0; i < n; ++i)
	for(int j = 0; j < m; ++j) {
	    int d = grid[i][j] - '0';
	    int x = i + a[d];
	    int y = j + b[d];

	    int u = getID(i, j);
	    if(x < 0 || x >= n || y < 0 || y >= m) go[u] = u;
	    else {
		int v = getID(x, y);
		go[u] = v;
		adj[v].push_back(u);
	    }
	}

    Tree.init();

    for(int i = 0; i < n * m; ++i)
	if(Tree.root(i) == Tree.root(go[i])) {
	    ++cntTree;
	    dfs0(i, i);
	}
	else Tree.merge(i, go[i]);
}

int dp[MAXN];
int sz;
int is[10][maxLen];

void dfs(int u) {
    dp[u] = 0;

    int x = u / m;
    int y = u % m;

    for(auto v: adj[u])
	if(!inCicle[v]) {
	    dfs(v);
	    dp[u] = max(dp[u], dp[v]);
	}

    if(dp[u] < sz && s[dp[u]] == grid[x][y]) ++dp[u];
}

bool solve() {
    sz = strlen(s);

    for(int i = 0; i < 10; ++i) is[i][sz] = 0;

    for(int i = sz - 1; i >= 0; --i) {
	for(int k = 0; k < 10; ++k) is[k][i] = is[k][i + 1];
	int d = s[i] - '0';
	is[d][i] = 1;
    }

    for(int i = 1; i <= cntTree; ++i) {
	int Max = 0;

	for(auto u: T[i].nodesInCicle) {
	    dfs(u);
	    Max = max(Max, dp[u]);
	}

	bool ok = true;

	for(int k = 0; k < 10; ++k)
	    if(is[k][Max] && !T[i].digit[k])
		ok = false;

	if(ok) return true;
    }

    return false;
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for(int i = 0; i < n; ++i) scanf(" %s", grid[i]);
    for(int i = 0; i < 10; ++i) scanf("%d %d", &a[i], &b[i]);
    build();
    while(q--) {
	scanf(" %s", s);
	if(solve()) printf("YES\n");
	else printf("NO\n");
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

#define debug(args...) fprintf(stderr, args);

const int maxn = 2e2 + 10;
const int MAXN = 4e4 + 10;
const int maxLen = 1e6 + 10;

int n, m, q;
char grid[maxn][maxn];

char s[maxLen];

int a[15], b[15];

vector<int> adj[MAXN];
int go[MAXN];

int getID(int x, int y) { return x * m + y; }

int cntTree;
struct tree {
    bool digit[10];
    vector<int> nodesInCicle;
} T[MAXN];

bool inCicle[MAXN];

struct dsu {
    int par[MAXN];
    int sz[MAXN];

    void init() {
	for(int i = 0; i < n * m; ++i) {
	    par[i] = i;
	    sz[i] = 1;
	}
    }

    int root(int v) {
	if(par[v] == v) return v;
	return par[v] = root(par[v]);
    }

    void merge(int x, int y) {
	x = root(x);
	y = root(y);
	if(x == y) return;
	if(sz[y] > sz[x]) swap(x, y);
	sz[x] += sz[y];
	par[y] = x;
    }
} Tree;

void dfs0(int v, int root) {
    int x = v / m;
    int y = v % m;
    int d = grid[x][y] - '0';

    T[cntTree].digit[d] = true;
    inCicle[v] = true;
    T[cntTree].nodesInCicle.push_back(v);

    if(go[v] != root) dfs0(go[v], root);
}

void build() {
    for(int i = 0; i < n; ++i)
	for(int j = 0; j < m; ++j) {
	    int d = grid[i][j] - '0';
	    int x = i + a[d];
	    int y = j + b[d];

	    int u = getID(i, j);
	    if(x < 0 || x >= n || y < 0 || y >= m) go[u] = u;
	    else {
		int v = getID(x, y);
		go[u] = v;
		adj[v].push_back(u);
	    }
	}

    Tree.init();

    for(int i = 0; i < n * m; ++i)
	if(Tree.root(i) == Tree.root(go[i])) {
	    ++cntTree;
	    dfs0(i, i);
	}
	else Tree.merge(i, go[i]);
}

int dp[MAXN];
int sz;
int is[10][MAXN];

void dfs(int u) {
    dp[u] = 0;

    int x = u / m;
    int y = u % m;

    for(auto v: adj[u])
	if(!inCicle[v]) {
	    dfs(v);
	    dp[u] = max(dp[u], dp[v]);
	}

    if(dp[u] < sz && s[dp[u]] == grid[x][y]) ++dp[u];
}

bool solve() {
    sz = strlen(s);

    for(int i = 0; i < 10; ++i) is[i][sz] = 0;

    for(int i = sz - 1; i >= 0; --i) {
	for(int k = 0; k < 10; ++k) is[k][i] = is[k][i + 1];
	int d = s[i] - '0';
	is[d][i] = 1;
    }

    for(int i = 1; i <= cntTree; ++i) {
	int Max = 0;

	for(auto u: T[i].nodesInCicle) {
	    dfs(u);
	    Max = max(Max, dp[u]);
	}

	bool ok = true;

	for(int k = 0; k < 10; ++k)
	    if(is[k][Max] && !T[i].digit[k])
		ok = false;

	if(ok) return true;
    }

    return false;
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for(int i = 0; i < n; ++i) scanf(" %s", grid[i]);
    for(int i = 0; i < 10; ++i) scanf("%d %d", &a[i], &b[i]);
    build();
    while(q--) {
	scanf(" %s", s);
	if(solve()) printf("YES\n");
	else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define N 210
#define M 50010
using namespace std;
int n,m,q,cnt,tot;
int head[M],a[M],b[M];
int c[N][N],id[N][N],nxt[M][12];
bool vis[N][N];
void dfs(int x,int y){
vis[x][y]=true;
int dx=x+a[c[x][y]],dy=y+b[c[x][y]];
if(dx<1||dx>n||dy<1||dy>m)dx=x,dy=y;
nxt[id[x][y]][c[x][y]]=id[dx][dy];
if(!vis[dx][dy])dfs(dx,dy);
for(int i=0;i<=9;i++)
if(i!=c[x][y])
nxt[id[x][y]][i]=nxt[id[dx][dy]][i];
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++){
char s[300];scanf("%s",s+1);
for(int j=1;j<=m;j++)
id[i][j]=++cnt,c[i][j]=s[j]-'0';
}
for(int i=0;i<=9;i++)scanf("%d%d",&a[i],&b[i]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(!vis[i][j]){
head[++tot]=id[i][j];
dfs(i,j);
}
while(q--){
char s[1000001];
scanf("%s",s+1);int len=strlen(s+1);
bool flag=false;
for(int i=1;i<=tot;i++){
int now=nxt[head[i]][s[1]-'0'],l=0;
while(l<len&&now!=0)
l++,now=nxt[now][s[l+1]-'0'];
if(l==len){
flag=true;break;
}
}
puts(flag?"YES":"NO");
}
return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 200;
const int T = 1000001;
const int D = 10;
const int V = N * N;

char s[T];
int len;
int gr[V];
int d[V];
int cy[V];
vector<int> rev[V];
int a[D], b[D];

inline bool contains(int v, char id) {
  return v & (1 << (id - '0'));
}

bool solve(int v, int l) {
  if (contains(d[v], s[l])) {
    --l;
    if (l < 0) {
      return true;
    }
  }
  for (int u: rev[v]) {
    if (solve(u, l)) {
      return true;
    }
  }
  return false;
}

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    for (int j = 0; j < m; ++j) {
      int v = i * m + j;
      gr[v] = s[j] - '0';
      d[v] = 1 << gr[v];
    }
  }
  for (int i = 0; i < D; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  int nv = n * m;
  for (int i = 0; i < nv; ++i) {
    int nr = i / m + a[gr[i]];
    int nc = i % m + b[gr[i]];
    if (0 <= nr && nr < n && 0 <= nc && nc < m) {
      gr[i] = nr * m + nc;
    } else {
      gr[i] = -1;
    }
  }
  // Builds cycles.
  memset(cy, -1, sizeof cy);
  for (int i = 0; i < nv; ++i) {
    if (cy[i] == -1) {
      vector<int> val;
      int j = i;
      while (j >= 0 && cy[j] == -1) {
        val.push_back(j);
        cy[j] = j;
        j = gr[j];
      }
      if (j >= 0) { // cycle
        while (val.back() != j) {
          d[j] |= d[val.back()];
          cy[val.back()] = j;
          val.pop_back();
        }
      }
    }
  }
  // Builds reverse tree.
  for (int v = 0; v < nv; ++v) {
    int u = gr[v];
    if (u >= 0 && cy[u] != cy[v]) {
      rev[cy[u]].push_back(v);
    }
  }
  for (int i = 0; i < q; ++i) {
    scanf("%s", s);
    len = strlen(s);
    bool ans = false;
    for (int v = 0; v < nv && !ans; ++v) {
      if (gr[v] == -1 || (cy[v] == v && cy[gr[v]] == v)) {
        // Cycle.
        int l = len - 1;
        while (l >= 0 && contains(d[v], s[l])) {
          --l;
        }
        if (l < 0) {
          ans = true;
        } else {
          ans = solve(v, l);
        }
      }
    }
    printf("%s\n", ans? "YES": "NO");
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 200;
const int T = 1000001;
const int D = 10;
const int V = N * N;

char s[T];
int len;
int gr[V];
int d[V];
int cy[V];
bool vis[N];
vector<int> rev[V];
int a[D], b[D];

inline bool contains(int v, char id) {
  return v & (1 << (id - '0'));
}

bool solve(int v, int l) {
  if (contains(d[v], s[l])) {
    --l;
    if (l < 0) {
      return true;
    }
  }
  for (int u: rev[v]) {
    if (solve(u, l)) {
      return true;
    }
  }
  return false;
}

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    for (int j = 0; j < m; ++j) {
      int v = i * m + j;
      gr[v] = s[j] - '0';
      d[v] = 1 << gr[v];
    }
  }
  for (int i = 0; i < D; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  int nv = n * m;
  for (int i = 0; i < nv; ++i) {
    int nr = i / m + a[gr[i]];
    int nc = i % m + b[gr[i]];
    if (0 <= nr && nr < n && 0 <= nc && nc < m) {
      gr[i] = nr * m + nc;
    } else {
      gr[i] = -1;
    }
  }
  // Builds cycles.
  memset(cy, -1, sizeof cy);
  for (int i = 0; i < nv; ++i) {
    if (!vis[i]) {
      vector<int> val;
      int j = i;
      while (j >= 0 && cy[j] == -1) {
        val.push_back(j);
        cy[j] = j;
        j = gr[j];
      }
      if (j >= 0 && !vis[j]) { // cycle
        for (int k = val.size() - 1; val[k] != j; --k) {
          d[j] |= d[val[k]];
          cy[val[k]] = j;
        }
      }
      for (int v: val) {
        vis[v] = true;
      }
    }
  }
  // Builds reverse tree.
  for (int v = 0; v < nv; ++v) {
    int u = gr[v];
    if (u >= 0 && cy[u] != cy[v]) {
      rev[cy[u]].push_back(v);
    }
  }
  for (int i = 0; i < q; ++i) {
    scanf("%s", s);
    len = strlen(s);
    bool ans = false;
    for (int v = 0; v < nv && !ans; ++v) {
      if (gr[v] == -1 || (cy[v] == v && cy[gr[v]] == v)) {
        // Cycle.
        int l = len - 1;
        while (l >= 0 && contains(d[v], s[l])) {
          --l;
        }
        if (l < 0) {
          ans = true;
        } else {
          ans = solve(v, l);
        }
      }
    }
    printf("%s\n", ans? "YES": "NO");
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 200;
const int T = 1000001;
const int D = 10;
const int V = N * N;

char s[T];
int len;
int gr[V];
int d[V];
int cy[V];
bool vis[V];
vector<int> rev[V];
int a[D], b[D];

inline bool contains(int v, char id) {
  return v & (1 << (id - '0'));
}

bool solve(int v, int l) {
  if (contains(d[v], s[l])) {
    --l;
    if (l < 0) {
      return true;
    }
  }
  for (int u: rev[v]) {
    if (solve(u, l)) {
      return true;
    }
  }
  return false;
}

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    for (int j = 0; j < m; ++j) {
      int v = i * m + j;
      gr[v] = s[j] - '0';
      d[v] = 1 << gr[v];
    }
  }
  for (int i = 0; i < D; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  int nv = n * m;
  for (int i = 0; i < nv; ++i) {
    int nr = i / m + a[gr[i]];
    int nc = i % m + b[gr[i]];
    if (0 <= nr && nr < n && 0 <= nc && nc < m) {
      gr[i] = nr * m + nc;
    } else {
      gr[i] = -1;
    }
  }
  // Builds cycles.
  memset(cy, -1, sizeof cy);
  for (int i = 0; i < nv; ++i) {
    if (!vis[i]) {
      vector<int> val;
      int j = i;
      while (j >= 0 && cy[j] == -1) {
        val.push_back(j);
        cy[j] = j;
        j = gr[j];
      }
      if (j >= 0 && !vis[j]) { // cycle
        for (int k = val.size() - 1; val[k] != j; --k) {
          d[j] |= d[val[k]];
          cy[val[k]] = j;
        }
      }
      for (int v: val) {
        vis[v] = true;
      }
    }
  }
  // Builds reverse tree.
  for (int v = 0; v < nv; ++v) {
    int u = gr[v];
    if (u >= 0 && cy[u] != cy[v]) {
      rev[cy[u]].push_back(v);
    }
  }
  for (int i = 0; i < q; ++i) {
    scanf("%s", s);
    len = strlen(s);
    bool ans = false;
    for (int v = 0; v < nv && !ans; ++v) {
      if (gr[v] == -1 || (cy[v] == v && cy[gr[v]] == v)) {
        // Cycle.
        int l = len - 1;
        while (l >= 0 && contains(d[v], s[l])) {
          --l;
        }
        if (l < 0) {
          ans = true;
        } else {
          ans = solve(v, l);
        }
      }
    }
    printf("%s\n", ans? "YES": "NO");
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 200;
const int T = 1000000;
const int D = 10;
const int V = N * N;

char s[T];
int len;
int gr[V];
int d[V];
int cy[V];
vector<int> rev[V];
bool vis[V];
int a[D], b[D];

inline bool contains(int v, char id) {
  return v & (1 << (id - '0'));
}

bool solve(int v, int l) {
  if (contains(d[v], s[l])) {
    --l;
    if (l < 0) {
      return true;
    }
  }
  for (int u: rev[v]) {
    if (solve(u, l)) {
      return true;
    }
  }
  return false;
}

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    for (int j = 0; j < m; ++j) {
      int v = i * m + j;
      gr[v] = s[j] - '0';
      d[v] = 1 << gr[v];
    }
  }
  for (int i = 0; i < D; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  int nv = n * m;
  for (int i = 0; i < nv; ++i) {
    int nr = i / m + a[gr[i]];
    int nc = i % m + b[gr[i]];
    if (0 <= nr && nr < n && 0 <= nc && nc < m) {
      gr[i] = nr * m + nc;
    } else {
      gr[i] = -1;
    }
  }
  // Builds cycles.
  memset(cy, -1, sizeof cy);
  for (int i = 0; i < nv; ++i) {
    if (cy[i] == -1) {
      vector<int> val;
      int j = i;
      while (j >= 0 && cy[j] == -1) {
        val.push_back(j);
        cy[j] = j;
        j = gr[j];
      }
      if (j >= 0) { // cycle
        while (val.back() != j) {
          d[j] |= d[val.back()];
          cy[val.back()] = j;
          val.pop_back();
        }
      }
    }
  }
  // Builds reverse tree.
  for (int v = 0; v < nv; ++v) {
    int u = gr[v];
    if (u >= 0 && cy[u] != cy[v]) {
      rev[cy[u]].push_back(v);
    }
  }
  for (int i = 0; i < q; ++i) {
    scanf("%s", s);
    len = strlen(s);
    bool ans = false;
    for (int v = 0; v < nv && !ans; ++v) {
      if (gr[v] == -1 || (cy[v] == v && cy[gr[v]] == v)) {
        // Cycle.
        int l = len - 1;
        while (l >= 0 && contains(d[v], s[l])) {
          --l;
        }
        if (l < 0) {
          ans = true;
        } else {
          ans = solve(v, l);
        }
      }
    }
    printf("%s\n", ans? "YES": "NO");
  }
  return 0;
}