Wilbur the pig now wants to play with strings. He has found an n by m table consisting only of the digits from 0 to 9 where the rows are numbered 1 to n and the columns are numbered 1 to m. Wilbur starts at some square and makes certain moves. If he is at square (x, y) and the digit d (0 ≤ d ≤ 9) is written at position (x, y), then he must move to the square (x + ad, y + bd), if that square lies within the table, and he stays in the square (x, y) otherwise. Before Wilbur makes a move, he can choose whether or not to write the digit written in this square on the white board. All digits written on the whiteboard form some string. Every time a new digit is written, it goes to the end of the current string.

Wilbur has q strings that he is worried about. For each string si, Wilbur wants to know whether there exists a starting position (x, y) so that by making finitely many moves, Wilbur can end up with the string si written on the white board.

Input

The first line of the input consists of three integers n, m, and q (1 ≤ n, m, q ≤ 200) — the dimensions of the table and the number of strings to process, respectively.

Each of the next n lines contains m digits from 0 and 9 giving the table itself.

Then follow 10 lines. The i-th of them contains the values ai - 1 and bi - 1 ( - 200 ≤ ai, bi ≤ 200), i.e. the vector that Wilbur uses to make a move from the square with a digit i - 1 in it.

There are q lines that follow. The i-th of them will contain a string si consisting only of digits from 0 to 9. It is guaranteed that the total length of these q strings won't exceed 1 000 000.

Output

For each of the q strings, print "YES" if Wilbur can choose x and y in order to finish with this string after some finite number of moves. If it's impossible, than print "NO" for the corresponding string.

Examples

Input

1 1 2
0
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
0000000000000
2413423432432


Output

YES
NO


Input

4 2 5
01
23
45
67
0 1
0 -1
0 1
0 -1
0 1
0 -1
0 1
0 -1
0 1
0 -1
0000000000
010101011101
32232232322
44343222342444324
6767


Output

YES
YES
YES
NO
YES

Note

In the first sample, there is a 1 by 1 table consisting of the only digit 0. The only move that can be made is staying on the square. The first string can be written on the white board by writing 0 repeatedly. The second string cannot be written as there is no 2 on the table.
//package codeforces.cfr331div2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by raggzy on 3/10/2016.
 */
public class E {
    private static int n;
    private static int m;
    private static Cell[][] cells;
    private static List<Cycle> cycles;

    private static boolean checkRange(int a, int r) {
        return 0 <= a && a < r;
    }

    private static class Cycle {
        private final List<Cell> cells;
        private boolean[] chars = new boolean[255];

        public Cycle(List<Cell> cells) {
            this.cells = cells;
        }
    }

    private static class Cell {
        private final char c;
        private List<Cell> inbound = new LinkedList<>();
        private Cell outbound;
        private Cycle cycle;
        private boolean was;

        private Cell(char c) {
            this.c = c;
        }
    }

    private static boolean findCycle(Cell cell, LinkedList<Cell> cells) {
        if (cells.size() > 0 && cell == cells.getLast()) {
            return true;
        }
        if (cell.was) {
            return false;
        }
        cells.push(cell);
        cell.was = true;
        for (Cell in : cell.inbound) {
            if (findCycle(in, cells)) {
                return true;
            }
        }
        cells.pop();
        return false;
    }

    private static void buildCycles() {
        cycles = new LinkedList<>();
        // finding cycles
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                Cell cell = cells[i][j];
                if (!cell.was) {
                    LinkedList<Cell> cycleCells = new LinkedList<>();
                    if (findCycle(cell, cycleCells)) {
                        cycles.add(new Cycle(cycleCells));
                    }
                }
            }
        }
        // building set of chars
        for (Cycle cycle : cycles) {
            for (Cell cell : cycle.cells) {
                cycle.chars[cell.c] = true;
                cell.cycle = cycle;
            }
        }
    }

    private static boolean testContains(Cell cell, String str, int pos) {
        if (pos == 0) {
            return true;
        }
        for (Cell in : cell.inbound) {
            if (in.cycle == null) {
                if (testContains(in, str, in.c == str.charAt(pos - 1) ? pos - 1 : pos)) {
                    return true;
                }
            }
        }
        return false;
    }

    private static boolean testContains(String str) {
        int[] lastIndex = new int[255];
        Arrays.fill(lastIndex, -1);
        for (int i = 0; i < str.length(); i++) {
            lastIndex[str.charAt(i)] = i;
        }
        for (Cycle cycle : cycles) {
            int pos = -1;
            for (char c = '0'; c <= '9'; c++) {
                if (!cycle.chars[c]) {
                    pos = Math.max(lastIndex[c], pos);
                }
            }
            for (Cell cell : cycle.cells) {
                if (testContains(cell, str, pos + 1)) {
                    return true;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                Cell cell = cells[i][j];
                if (cell.cycle == null && cell.outbound == null) {
                    if (testContains(cell, str, str.length())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }


    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] tmp = in.readLine().split(" ");
        n = Integer.valueOf(tmp[0]);
        m = Integer.valueOf(tmp[1]);
        int q = Integer.valueOf(tmp[2]);

        cells = new Cell[n][m];
        for (int i = 0; i < n; i++) {
            String line = in.readLine();
            for (int j = 0; j < m; j++) {
                cells[i][j] = new Cell(line.charAt(j));
            }
        }

        int[] x = new int[255];
        int[] y = new int[255];
        for (char i = '0'; i <= '9'; i++) {
            tmp = in.readLine().split(" ");
            x[i] = Integer.valueOf(tmp[0]);
            y[i] = Integer.valueOf(tmp[1]);
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                Cell cell = cells[i][j];
                int nx = i + x[cell.c];
                int ny = j + y[cells[i][j].c];
                if (checkRange(nx, n) && checkRange(ny, m)) {
                    cells[nx][ny].inbound.add(cell);
                    cell.outbound = cells[nx][ny];
                } else {
                    cell.inbound.add(cell);
                }
            }
        }

        buildCycles();

        for (int c = 0; c < q; c++) {
            System.out.println(testContains(in.readLine()) ? "YES" : "NO");
        }
    }
}
