Problem: Pay attention to the output section below, where you will see the information about flushing the output.

Bearland is a grid with h rows and w columns. Rows are numbered 1 through h from top to bottom. Columns are numbered 1 through w from left to right. Every cell is either allowed (denoted by '.' in the input) or permanently blocked (denoted by '#').

Bearland is a cold land, where heavy snow often makes travelling harder. Every day a few allowed cells are temporarily blocked by snow. Note, that this block works only on this particular day and next day any of these cells might be allowed again (unless there is another temporarily block).

It's possible to move directly between two cells only if they share a side and none of them is permanently or temporarily blocked.

Limak is a little polar bear who lives in Bearland. His house is at the top left cell, while his school is at the bottom right cell. Every day Limak should first go from his house to the school and then return back to his house. Since he gets bored easily, he doesn't want to visit the same cell twice on one day, except for the cell with his house, where he starts and ends. If Limak can reach a school and return home avoiding revisiting cells, he calls a day interesting.

There are q days you must process, one after another. For each of these days you should check if it's interesting and print "YES" or "NO" on a separate line. In order to be able to read the description of the next day you should print the answer for the previous one and flush the output.

It's guaranteed that a day with no cells temporarily blocked by snow would be interesting. It's also guaranteed that cells with Limak's house and school are never blocked (neither permanently or temporarily).

Input

The first line of the input contains three integers h, w and q (2 ≤ h, w ≤ 1000, 1 ≤ q ≤ 10 000) — the height and the width of the grid, and the number of days, respectively.

Next h lines describe which cells are allowed and which permanently blocked. The i-th line contains a string of length w, describing the i-th row. Every character is either '.' (denoting an allowed cell) or '#' (denoting a permanently blocked cell). It's guaranteed that a day with no cells temporarily blocked by snow would be interesting.

Then, the description of q days is given. The description of the i-th day starts with a line containing a single integer ki (1 ≤ ki ≤ 10) — the number of cells that are temporarily blocked by snow on that day. Each of next ki lines contains two integers ri, j and ci, j (1 ≤ ri, j ≤ h, 1 ≤ ci, j ≤ w), representing a cell at the intersection of the row ri, j and the column ci, j. The given ki cells are distinct and none of them is permanently blocked. Also, none of them contains Limak's house or school.

Output

For each of q days print "YES" if that day is interesting, and otherwise print "NO", both without the quotes. After printing an answer, you have to both print the end-of-line character and flush the output. Then you can proceed to the next day. You can get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output.

To flush you can use (just after printing a YES/NO and end-of-line): 

  * fflush(stdout) in C++; 
  * System.out.flush() in Java; 
  * stdout.flush() in Python; 
  * flush(output) in Pascal; 
  * See the documentation for other languages. 

Examples

Input

3 5 4
.....
.....
.#...
1
1 4
1
1 5
2
2 4
3 1
2
1 5
3 3


Output

NO
YES
YES
NO


Input

9 31 5
...............................
...............................
.###.###.#.###...###.###.#.###.
...#.#.#.#.#.......#.#.#.#...#.
.###.#.#.#.###...###.#.#.#...#.
.#...#.#.#.#.#...#...#.#.#...#.
.###.###.#.###...###.###.#...#.
...............................
...............................
5
6 5
2 11
1 14
8 15
2 14
5
2 14
1 14
8 16
6 5
2 11
3
2 2
1 4
8 30
10
3 1
3 11
5 16
7 21
4 16
3 5
7 31
3 9
7 25
3 27
10
3 1
3 9
7 25
3 27
7 21
4 17
3 5
7 31
4 16
3 11


Output

NO
YES
YES
YES
NO

Note

In the first sample, there are 4 days. Drawings below show how Limak could go to school and return to his home in the second and the third day (on the left and on the right respectively). A permanently blocked cell is painted red, while cells temporarily blocked by snow are painted orange. Black and green arrows should Limak's way to the school and back to the house respectively.

<image>

For the second sample, below you can see how the grid looks like on each day, where '#' denotes a cell that is blocked, either temporarily or permanently.

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long P = 998244353;
const int N = 1e3 + 5;
const int INF = 1e9;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void print(long long x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void pls(long long &x, long long y) {
  x += y;
  if (x >= P) x -= P;
}
int h, w, Q, cnt;
char s[N];
int a[N][N];
int num[N][N];
int fa[N * N], sz[N * N], blo[N * N];
bool visL[N * N], visR[N * N];
int K;
struct Node {
  int x, y;
} p[15];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int tp;
int q[N * N];
map<int, int> mp[N * N];
int gettop(int x) {
  while (fa[x] != x) x = fa[x];
  return x;
}
void merge(int x, int y) {
  int u = gettop(x), v = gettop(y);
  if (u == v) return;
  if (sz[u] > sz[v]) swap(u, v);
  fa[u] = v;
  sz[v] += sz[u];
  q[++tp] = u;
  return;
}
void MAIN() {
  int nx, ny, mx, my, u, v;
  scanf("%d%d%d", &h, &w, &Q);
  for (int i = 0; i <= h + 1; ++i) {
    for (int j = 0; j <= w + 1; ++j) {
      a[i][j] = 0;
      if (i == 0 && j >= 3) a[i][j] = 1;
      if (j == 0 && i >= 3) a[i][j] = 1;
      if (i == h + 1 && j <= w - 2) a[i][j] = 1;
      if (j == w + 1 && i <= h - 2) a[i][j] = 1;
    }
  }
  for (int i = 1; i <= h; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= w; ++j) {
      if (s[j] == '#')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  }
  cnt = 0;
  for (int i = 0; i <= h + 1; ++i) {
    for (int j = 0; j <= w + 1; ++j) {
      num[i][j] = ++cnt;
      fa[cnt] = cnt;
      sz[cnt] = 1;
    }
  }
  tp = 0;
  for (int i = 0; i <= h + 1; ++i) {
    for (int j = 0; j <= w + 1; ++j) {
      if (!a[i][j]) continue;
      for (int xxx = -1; xxx <= 1; ++xxx) {
        for (int yyy = -1; yyy <= 1; ++yyy) {
          nx = i + xxx;
          ny = j + yyy;
          if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 || a[nx][ny] == 0)
            continue;
          u = find(num[i][j]);
          v = find(num[nx][ny]);
          if (u != v) fa[v] = u;
        }
      }
    }
  }
  for (int i = 0; i <= h + 1; ++i) {
    for (int j = 0; j <= w + 1; ++j) {
      u = find(num[i][j]);
      blo[num[i][j]] = fa[num[i][j]];
    }
  }
  for (int i = 0; i <= h + 1; ++i) {
    for (int j = 0; j <= w + 1; ++j) {
      if (!a[i][j]) continue;
      for (int xxx = -2; xxx <= 2; ++xxx) {
        for (int yyy = -2; yyy <= 2; ++yyy) {
          nx = i + xxx;
          ny = j + yyy;
          if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 || a[nx][ny] == 0)
            continue;
          u = blo[num[i][j]];
          v = blo[num[nx][ny]];
          if (u == v) continue;
          mp[u][v] = 1;
          mp[v][u] = 1;
          if (v == blo[num[0][w + 1]]) visR[u] = 1;
          if (u == blo[num[0][w + 1]]) visR[v] = 1;
          if (v == blo[num[h + 1][0]]) visL[u] = 1;
          if (u == blo[num[h + 1][0]]) visL[v] = 1;
        }
      }
    }
  }
  while (Q--) {
    scanf("%d", &K);
    for (int i = 1; i <= K; ++i) {
      scanf("%d%d", &p[i].x, &p[i].y);
      a[p[i].x][p[i].y] = 1;
    }
    bool flag = 0;
    if (blo[num[h + 1][0]] == blo[num[0][w + 1]]) flag = 1;
    if (mp[blo[num[h + 1][0]]][blo[num[0][w + 1]]]) flag = 1;
    if (!flag) {
      for (int i = 1; i <= K; ++i) {
        for (int xxx = -1; xxx <= 1; ++xxx) {
          for (int yyy = -1; yyy <= 1; ++yyy) {
            nx = p[i].x + xxx;
            ny = p[i].y + yyy;
            if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 || a[nx][ny] == 0)
              continue;
            merge(num[p[i].x][p[i].y], num[nx][ny]);
          }
        }
      }
      if (gettop(num[h + 1][0]) == gettop(num[0][w + 1])) flag = 1;
      for (int i = 1; i <= K; ++i) {
        if (gettop(num[h + 1][0]) == gettop(num[p[i].x][p[i].y])) {
          for (int xxx = -2; xxx <= 2; ++xxx) {
            for (int yyy = -2; yyy <= 2; ++yyy) {
              nx = p[i].x + xxx;
              ny = p[i].y + yyy;
              if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 ||
                  a[nx][ny] == 0)
                continue;
              if (gettop(num[0][w + 1]) == gettop(num[nx][ny])) flag = 1;
            }
          }
        }
        if (gettop(num[0][w + 1]) == gettop(num[p[i].x][p[i].y])) {
          for (int xxx = -2; xxx <= 2; ++xxx) {
            for (int yyy = -2; yyy <= 2; ++yyy) {
              nx = p[i].x + xxx;
              ny = p[i].y + yyy;
              if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 ||
                  a[nx][ny] == 0)
                continue;
              if (gettop(num[h + 1][0]) == gettop(num[nx][ny])) flag = 1;
            }
          }
        }
      }
      for (int i = 1; i <= K; ++i) {
        if (gettop(num[h + 1][0]) == gettop(num[p[i].x][p[i].y])) {
          for (int xxx = -1; xxx <= 1; ++xxx) {
            for (int yyy = -1; yyy <= 1; ++yyy) {
              nx = p[i].x + xxx;
              ny = p[i].y + yyy;
              if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 ||
                  a[nx][ny] == 0)
                continue;
              if (visR[blo[num[nx][ny]]]) flag = 1;
            }
          }
        }
        if (gettop(num[0][w + 1]) == gettop(num[p[i].x][p[i].y])) {
          for (int xxx = -1; xxx <= 1; ++xxx) {
            for (int yyy = -1; yyy <= 1; ++yyy) {
              nx = p[i].x + xxx;
              ny = p[i].y + yyy;
              if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 ||
                  a[nx][ny] == 0)
                continue;
              if (visL[blo[num[nx][ny]]]) flag = 1;
            }
          }
        }
      }
      for (int i = 1; i <= K; ++i) {
        for (int j = i + 1; j <= K; ++j) {
          if ((gettop(num[h + 1][0]) == gettop(num[p[i].x][p[i].y]) &&
               gettop(num[0][w + 1]) == gettop(num[p[j].x][p[j].y])) ||
              (gettop(num[h + 1][0]) == gettop(num[p[j].x][p[j].y]) &&
               gettop(num[0][w + 1]) == gettop(num[p[i].x][p[i].y]))) {
            for (int xxx = -1; xxx <= 1; ++xxx) {
              for (int yyy = -1; yyy <= 1; ++yyy) {
                for (int xx = -1; xx <= 1; ++xx) {
                  for (int yy = -1; yy <= 1; ++yy) {
                    nx = p[i].x + xxx;
                    ny = p[i].y + yyy;
                    mx = p[j].x + xx;
                    my = p[j].y + yy;
                    if (nx < 0 || ny < 0 || nx > h + 1 || ny > w + 1 ||
                        a[nx][ny] == 0)
                      continue;
                    if (mx < 0 || my < 0 || mx > h + 1 || my > w + 1 ||
                        a[mx][my] == 0)
                      continue;
                    if (mp[blo[num[nx][ny]]][blo[num[mx][my]]]) flag = 1;
                  }
                }
              }
            }
          }
        }
      }
      while (tp > 0) {
        sz[fa[q[tp]]] -= sz[q[tp]];
        fa[q[tp]] = q[tp];
        tp--;
      }
    }
    if (flag)
      puts("NO");
    else
      puts("YES");
    fflush(stdout);
    for (int i = 1; i <= K; ++i) {
      a[p[i].x][p[i].y] = 0;
    }
  }
  return;
}
int main() {
  int ttt = 1;
  while (ttt--) MAIN();
  return 0;
}