#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=1000;
const int MAXW=1000;
const int MAXB=10;
const int MAXSEG=2+9*MAXB;
const int MAXC=2*MAXH*MAXW+2;
const int MAXFREQ=5;
const int MAXP=MAXFREQ*MAXH*MAXW;
const int DX[]={-1,0,+1,0},DY[]={0,+1,0,-1};

int h,w,nq;
char g[MAXH][MAXW+1];
int ncyc;
int clen[MAXC];
int coff[MAXC+1];
int np;
int px[MAXP],py[MAXP],pd[MAXP];
int pcyc[MAXH][MAXW][MAXFREQ],pcycidx[MAXH][MAXW][MAXFREQ],pcyccnt[MAXH][MAXW];
int topcyc,botcyc;
int xycyc[MAXH][MAXW];
int xydcyc[MAXH][MAXW][4],xydcycidx[MAXH][MAXW][4];
set<ll> common;

int normidx(int c,int idx) { while(idx<0) idx+=clen[c]; while(idx>=clen[c]) idx-=clen[c]; return idx; }
int getcycx(int c,int idx) { return px[coff[c]+idx]; }
int getcycy(int c,int idx) { return py[coff[c]+idx]; }
int getcycd(int c,int idx) { return pd[coff[c]+idx]; }

int createcyc(int sx,int sy,int sd) {
	//printf("createcyc(%d,%d,%d)\n\t",sx,sy,sd);
	int x=sx,y=sy,d=sd,c=ncyc++; clen[c]=0;
	while(true) {
		int p=np++; ++clen[c]; int nx,ny;
		if(sx==0&&sy==0&&sd==0&&x==h-1&&y==w-1&&d==1) d=4;
		if(sx==h-1&&sy==w-1&&sd==2&&x==0&&y==0&&d==3) d=4;
		while(d!=4) {
			nx=x+DX[d],ny=y+DY[d];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]=='.') break;
			assert(xydcyc[x][y][d]==-1); xydcyc[x][y][d]=c; xydcycidx[x][y][d]=p-coff[c];
			d=(d+1)%4;
		}
		px[p]=x,py[p]=y,pd[p]=d;
		//printf("(%d,%d,%d)",x,y,d);
		if(d==4||nx==sx&&ny==sy) break;
		x=nx,y=ny,d=(d+3)%4;
	}
	//puts("");
	coff[ncyc]=coff[c]+clen[c]; return c;
}
void precalc() {
	ncyc=0,np=0; coff[0]=0; memset(xydcyc,-1,sizeof(xydcyc)); memset(xydcycidx,-1,sizeof(xydcycidx)); memset(xycyc,-1,sizeof(xycyc));
	topcyc=createcyc(0,0,0);
	botcyc=createcyc(h-1,w-1,2);
	static int qx[MAXH*MAXW],qy[MAXH*MAXW],qhead,qtail; static bool reach[MAXH][MAXW]; qhead=qtail=0; memset(reach,false,sizeof(reach)); qx[qhead]=0,qy[qhead]=0,++qhead,reach[0][0]=true;
	while(qtail<qhead) {
		int x=qx[qtail],y=qy[qtail]; ++qtail;
		REP(k,4) { int nx=x+DX[k],ny=y+DY[k]; if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]=='.'&&!reach[nx][ny]) qx[qhead]=nx,qy[qhead]=ny,++qhead,reach[nx][ny]=true; }
	}
	REP(x,h) REP(y,w) if(reach[x][y]) REP(k,4) { int nx=x+DX[k],ny=y+DY[k]; if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]!='.'&&xydcyc[x][y][k]==-1) createcyc(x,y,k); }
	REP(x,h) REP(y,w) if(g[x][y]=='.') { int c=xycyc[x][y]=ncyc++; int p=np++; px[p]=x,py[p]=y,pd[p]=4; clen[c]=1; coff[ncyc]=coff[c]+clen[c]; }

	//REP(c,ncyc) if(clen[c]>1) { printf("%d:",c); FOR(j,coff[c],coff[c+1]) printf(" (%d,%d,%d)",px[j],py[j],pd[j]); puts(""); }
	memset(pcyccnt,0,sizeof(pcyccnt)); REP(c,ncyc) FOR(j,coff[c],coff[c+1]) { int x=px[j],y=py[j],d=pd[j]; int i=pcyccnt[x][y]++; pcyc[x][y][i]=c; pcycidx[x][y][i]=j-coff[c]; }
	common.clear(); REP(x,h) REP(y,w) REP(i,pcyccnt[x][y]) REP(j,pcyccnt[x][y]) if(pcyc[x][y][i]<pcyc[x][y][j]) common.insert((ll)ncyc*pcyc[x][y][i]+pcyc[x][y][j]); common.erase((ll)ncyc*topcyc+botcyc); common.erase((ll)ncyc*botcyc+topcyc);
	//for(set<pair<int,int> >::iterator it=common.begin();it!=common.end();++it) { int a=it->first,b=it->second; if(off[a+1]-off[a]<=1||off[b+1]-off[b]<=1) continue; printf("%d-%d\n",a,b); }
}

typedef struct Seg { int cyc,l,r,len,nd,prv,nxt; } Seg;

int nb;
int bx[MAXB],by[MAXB];
int bcnt[MAXB],bat[MAXB],bseg[MAXB],bpos[MAXB];
int q[4*MAXB],qhead,qtail;

int shead[2];
Seg seg[MAXSEG]; int scnt;

void printpath(int s) {
	while(seg[s].prv!=-1) s=seg[s].prv;
	for(;s!=-1;s=seg[s].nxt) {
		printf("\t\t[%d,%d]",getcycx(seg[s].cyc,seg[s].l),getcycy(seg[s].cyc,seg[s].l)); if(seg[s].l!=seg[s].r) printf("-[%d,%d]",getcycx(seg[s].cyc,seg[s].r),getcycy(seg[s].cyc,seg[s].r));
		printf("<%d-%d-%d>(%d)\n",seg[s].prv,s,seg[s].nxt,seg[s].len);
	}
}
int createseg(int cyc,int l,int r,int len,int nd) { seg[scnt].cyc=cyc,seg[scnt].l=l,seg[scnt].r=r,seg[scnt].len=len,seg[scnt].nd=nd,seg[scnt].prv=seg[scnt].nxt=-1; return scnt++; }
bool xyoncyc(int x,int y,int i,int c) {
	return pcyc[x][y][i]==c;
}
int getxycycpos(int x,int y,int i,int c) {
	return pcycidx[x][y][i];
}
bool xyonseg(int x,int y,int i,int s) {
	if(pcyc[x][y][i]==seg[s].cyc) {
		int idx=pcycidx[x][y][i];
		if(seg[s].l<=seg[s].r&&seg[s].l<=idx&&idx<=seg[s].r) return true;
		if(seg[s].l>seg[s].r&&(idx<=seg[s].r||idx>=seg[s].l)) return true;
	}
	return false;
}
int getxysegpos(int x,int y,int i,int s) {
	if(pcyc[x][y][i]==seg[s].cyc) {
		int idx=pcycidx[x][y][i];
		if(seg[s].l<=seg[s].r&&seg[s].l<=idx&&idx<=seg[s].r) return idx-seg[s].l;
		if(seg[s].l>seg[s].r&&(idx<=seg[s].r||idx>=seg[s].l)) return idx-seg[s].l+(idx<=seg[s].r?clen[seg[s].cyc]:0);
	}
	assert(false); return -1;
}
bool bonseg(int b,int i,int s) { return xyonseg(bx[b],by[b],i,s); }
bool banyonseg(int b,int s) {
	REP(j,pcyccnt[bx[b]][by[b]]) if(bonseg(b,j,s)) return true;
	return false;
}
int getbsegpos(int b,int i,int s) { return getxysegpos(bx[b],by[b],i,s); }
int getonlybsegpos(int b,int s) {
	int ret=-1; REP(j,pcyccnt[bx[b]][by[b]]) if(bonseg(b,j,s)) { assert(ret==-1); ret=getbsegpos(b,j,s); } assert(ret!=-1); return ret;
}
int findnxtcycpos(int c,int idx,int x,int y) {
	int ret=-1;
	//printf("findnxtcycpos(%d,%d,%d,%d)\n",c,idx,x,y);
	REP(j,pcyccnt[x][y]) if(xyoncyc(x,y,j,c)) {
		int cur=getxycycpos(x,y,j,c); //printf("\t%d\n",cur);
		if(ret==-1||(ret>=idx&&cur>=idx&&cur<ret||ret<idx&&(cur>=idx||cur<ret))) ret=cur;
	}
	assert(ret!=-1); return ret;
}
void getsegxyd(int s,int pos,int &x,int &y,int &d) {
	int idx=normidx(seg[s].cyc,seg[s].l+pos);
	x=getcycx(seg[s].cyc,idx),y=getcycy(seg[s].cyc,idx),d=pos==seg[s].len-1?seg[s].nd:getcycd(seg[s].cyc,idx);
}
void ssplit(int s,int pos,int &pseg,int &nseg) {
	while(pos<=0) { assert(seg[s].prv!=-1); s=seg[s].prv; pos+=seg[s].len; }
	while(pos>seg[s].len) { assert(seg[s].nxt!=-1); pos-=seg[s].len; s=seg[s].nxt; }
	if(pos==seg[s].len) { assert(seg[s].nxt!=-1); pseg=s,nseg=seg[s].nxt; seg[pseg].nxt=seg[nseg].prv=-1; return; }
	int nr=normidx(seg[s].cyc,seg[s].l+pos-1),nl=normidx(seg[s].cyc,seg[s].l+pos);
	nseg=createseg(seg[s].cyc,nl,seg[s].r,seg[s].len-pos,seg[s].nd); seg[nseg].nxt=seg[s].nxt; if(seg[nseg].nxt!=-1) seg[seg[nseg].nxt].prv=nseg;
	pseg=s,seg[pseg].r=nr,seg[pseg].len=pos,seg[pseg].nd=getcycd(seg[s].cyc,nr);
	seg[pseg].nxt=-1,seg[nseg].prv=-1;
	REP(i,nb) if(bcnt[i]==1&&bseg[i]==pseg&&bpos[i]>=pos) bseg[i]=nseg,bpos[i]-=pos;
}
void smerge(int pseg,int d,int nseg) {
	seg[pseg].nxt=nseg; seg[pseg].nd=d; seg[nseg].prv=pseg;
}
void sadd(int at,int nseg) {
	//printf("sadd(%d,%d)\n",at,nseg);
	REP(i,nb) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,nseg)) {
		int pos=getbsegpos(i,j,nseg);
		++bcnt[i],bat[i]=at,bseg[i]=nseg,bpos[i]=pos,q[qhead++]=i;
		//printf("\t\tadding (%d,%d) on (%d,%d) [%d]\n",bx[i],by[i],bseg[i],bpos[i],bat[i]);
		assert(bcnt[i]==1);
	}
}
void sremove(int s) {
	while(seg[s].prv!=-1) s=seg[s].prv;
	while(s!=-1) {
		REP(i,nb) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
			--bcnt[i];
			//printf("\t\tremoving (%d,%d)\n",bx[i],by[i]);
			assert(bcnt[i]==0);
		}
		s=seg[s].nxt;
	}
}
bool intersectspath(int s,int at) {
	for(int ss=shead[at];ss!=-1;ss=seg[ss].nxt) {
		int a=seg[s].cyc,b=seg[ss].cyc;
		if(a>b) swap(a,b);
		if(a==b||common.count((ll)a*ncyc+b)) return true;
	}
	return false;
}
void fixprefix(int &lst,int &d,int &s) {
	REP(i,nb) if(bcnt[i]>0) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
		int ss=lst; while(ss!=-1&&!banyonseg(i,ss)) ss=seg[ss].prv; if(ss==-1) continue;
		int spos=getbsegpos(i,j,s),sspos=getonlybsegpos(i,ss);
		int ss1,ss2; ssplit(ss,sspos,ss1,ss2); lst=ss1; d=seg[ss1].nd; sremove(ss2);
		if(spos!=0) { int s1,s2; ssplit(s,spos,s1,s2); s=s2; }
	}
}
bool fixsuffix(int &s,int &d,int &fst) {
	bool ret=false;
	REP(i,nb) if(bcnt[i]>0) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
		int ss=fst; while(ss!=-1&&!banyonseg(i,ss)) ss=seg[ss].nxt; if(ss==-1) continue;
		int spos=getbsegpos(i,j,s),sspos=getonlybsegpos(i,ss);
		int ss1,ss2; ssplit(ss,sspos+1,ss1,ss2); fst=ss2; d=seg[ss1].nd; sremove(ss1);
		if(spos!=seg[s].len-1) { int s1,s2; ssplit(s,spos+1,s1,s2); s=s1; }
		ret=true;
	}
	if(ret) return ret;
	int vx=getcycx(seg[s].cyc,seg[s].r),vy=getcycy(seg[s].cyc,seg[s].r),wx=getcycx(seg[fst].cyc,seg[fst].l),wy=getcycy(seg[fst].cyc,seg[fst].l);
	//printf("fixsuffix -> (%d,%d) / (%d,%d) [%d:%d,%d]\n",vx,vy,wx,wy,s,seg[s].cyc,seg[s].r);
	if(vx==wx&&vy==wy) {
		int ss=fst,ss1,ss2; ssplit(ss,1,ss1,ss2); fst=ss2; d=seg[ss1].nd; sremove(ss1);
		ret=true;
	}
	return ret;
}

void fixinternal(int &s) {
	int mn[MAXB],mx[MAXB]; REP(i,nb) mn[i]=mx[i]=-1;
	REP(i,nb) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
		int cur=getbsegpos(i,j,s);
		if(mn[i]==-1||cur<mn[i]) mn[i]=cur;
		if(mx[i]==-1||cur>mx[i]) mx[i]=cur;
	}
	while(true) {
		//REP(i,nb) if(mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]) printf("%d: %d..%d\n",i,mn[i],mx[i]);
		int bidx=-1; REP(i,nb) if(mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]&&(bidx==-1||mx[i]>mx[bidx])) bidx=i; /*printf("=>%d\n",bidx);*/ if(bidx==-1) return;
		REP(i,nb) if(mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]) assert(mn[bidx]<=mn[i]&&mx[i]<=mx[bidx]||mx[i]<mn[bidx]);
		if(mn[bidx]==0) {
			int s3,s4; ssplit(s,mx[bidx]-mn[bidx],s3,s4);
			//printpath(s3); puts(""); printpath(s4); puts("");
			s=s4;
		} else {
			int s1,s2; ssplit(s,mn[bidx],s1,s2); int s3,s4; ssplit(s2,mx[bidx]-mn[bidx],s3,s4);
			//printpath(s1); puts(""); printpath(s2); puts(""); printpath(s3); puts(""); printpath(s4); puts("");
			smerge(s1,seg[s1].nd,s4); s=s1;
		}
		REP(i,nb) if(i!=bidx&&mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]&&mx[i]>=mn[bidx]) mn[i]=mx[i]=-1; mn[bidx]=mx[bidx]=-1;
	}
}

bool solve() {
	// two paths of segments
	// invariant: the two paths do not intersect
	// invariant: each blocked node occurs on at most one segment
	qhead=qtail=scnt=0; memset(bcnt,0,sizeof(bcnt));
	shead[0]=createseg(topcyc,0,clen[topcyc]-1,clen[topcyc],4); sadd(0,shead[0]);
	shead[1]=createseg(botcyc,0,clen[botcyc]-1,clen[botcyc],4); sadd(1,shead[1]);
	while(qtail<qhead) {
		int bidx=q[qtail++],at=bat[bidx];
		if(bcnt[bidx]!=1) continue;
		//printf("processing (%d,%d) on (%d,%d) [%d]\n",bx[bidx],by[bidx],bseg[bidx],bpos[bidx],bat[bidx]); printpath(bseg[bidx]); puts("");
		int sseg,pseg,qseg,tseg; ssplit(bseg[bidx],bpos[bidx],sseg,pseg); ssplit(pseg,1,qseg,tseg); sremove(qseg); //printpath(sseg); puts(""); printpath(tseg); puts("");
		int sx,sy,sd; getsegxyd(sseg,seg[sseg].len-1,sx,sy,sd);
		int tx,ty,td; getsegxyd(tseg,0,tx,ty,td);
		//printf("(%d,%d)-(%d,%d)\n",sx,sy,tx,ty);
		int cseg=sseg,cx=sx,cy=sy,cd=sd;
		if(sx==tx&&sy==ty) {
			int s1,s2; ssplit(tseg,1,s1,s2); sremove(s1); smerge(sseg,seg[s1].nd,s2);
		} else while(true) {
			if(cx+DX[cd]==bx[bidx]&&cy+DY[cd]==by[bidx]) cd=(cd+1)%4;
			//printf("\t(%d,%d)+%d->(%d,%d)\n",cx,cy,cd,cx+DX[cd],cy+DY[cd]);
			int vx=cx+DX[cd],vy=cy+DY[cd]; assert(vx>=0&&vx<h&&vy>=0&&vy<w);
			int wx,wy,wd,nseg;
			if(g[vx][vy]=='.') {
				//printf("\t\tempty\n");
				wx=vx,wy=vy,wd=(cd+3)%4;
				nseg=createseg(xycyc[vx][vy],0,0,1,wd);
			} else {
				//printf("\t\tfull\n");
				int c=xydcyc[cx][cy][cd],idx=xydcycidx[cx][cy][cd]; assert(c!=-1&&idx!=-1&&getcycx(c,idx)==cx&&getcycy(c,idx)==cy);
				cd=getcycd(c,idx); int sidx=normidx(c,idx+1);
				int tidx=findnxtcycpos(c,sidx,bx[bidx],by[bidx]); tidx=normidx(c,tidx-1);
				vx=getcycx(c,sidx),vy=getcycy(c,sidx),wx=getcycx(c,tidx),wy=getcycy(c,tidx),wd=getcycd(c,tidx);
				int len=tidx-sidx+1; if(len<=0) len+=clen[c];
				nseg=createseg(c,sidx,tidx,len,wd); // nseg=segment starting at (vx,vy) and ending at (wx,wy) with direction wd such that wx+DX[wd]==bx[bidx] && wy+DY[wd]==by[bidx]
				//printf("\t\t[%d,%d]->[%d,%d]+%d <%d>\n",vx,vy,wx,wy,wd,c);
			}
			if(intersectspath(nseg,1-at)) return false;
			fixprefix(cseg,cd,nseg);
			bool done=fixsuffix(nseg,wd,tseg);
			fixinternal(nseg);
			//printf("final: (at=%d)\n",at); printpath(nseg); puts("");
			for(int s=nseg;s!=-1;s=seg[s].nxt) sadd(at,s);
			smerge(cseg,cd,nseg);
			//printf("becoming: (at=%d)\n",at); printpath(nseg); puts("");
			while(seg[nseg].nxt!=-1) nseg=seg[nseg].nxt;
			if(done) { smerge(nseg,wd,tseg); break; }
			cseg=nseg,cx=wx,cy=wy,cd=wd;
		}
		//REP(i,2) { printf("\t%s:\n",i==0?"TOP":"BOTTOM"); printpath(shead[i]); }
	}
	return true;
}

void run() {
	scanf("%d%d%d",&h,&w,&nq);
	REP(x,h) scanf("%s",g[x]);
	precalc();
	REP(i,nq) {
		scanf("%d",&nb); REP(j,nb) scanf("%d%d",&bx[j],&by[j]),--bx[j],--by[j];
		bool have=solve();
		printf("%s\n",have?"YES":"NO"); fflush(stdout);
	}
}

int main() {
	run();
	return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=1000;
const int MAXW=1000;
const int MAXB=10;
const int MAXID=2*MAXH*MAXW+2;
const int MAXFREQ=6;
const int MAXP=MAXFREQ*MAXH*MAXW;
const int DX[]={-1,0,+1,0,0},DY[]={0,+1,0,-1,0};

int h,w,nq;
char g[MAXH][MAXW+1];
bool reach[MAXH][MAXW];

int nid;
int pid[MAXH][MAXW];
int topid,botid;
int cycid[MAXH][MAXW];
int cycpos[MAXH][MAXW][4];
int off[MAXID+1];
int px[MAXP],py[MAXP],pd[MAXP],np;
int occ[MAXH][MAXW][MAXFREQ],occpos[MAXH][MAXW][MAXFREQ],nocc[MAXH][MAXW];
set<ll> common;

int normpos(int id,int pos) {
	int len=off[id+1]-off[id];
	while(pos<0) pos+=len; while(pos>=len) pos-=len; return pos;
}
void getp(int id,int pos,int &x,int &y,int &d) {
	x=px[off[id]+pos],y=py[off[id]+pos],d=pd[off[id]+pos];
}

int createcyc(int sx,int sy,int sd) {
	//printf("createcyc(%d,%d,%d)\n\t",sx,sy,sd);
	int x=sx,y=sy,d=sd,id=nid++; int len=0;
	while(true) {
		int p=np++; ++len; int nx,ny;
		if(sx==0&&sy==0&&sd==0&&x==h-1&&y==w-1&&d==1) d=4;
		if(sx==h-1&&sy==w-1&&sd==2&&x==0&&y==0&&d==3) d=4;
		while(d!=4) {
			nx=x+DX[d],ny=y+DY[d];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]=='.') break;
			if(0<=nx&&nx<h&&0<=ny&&ny<w) { assert(cycid[nx][ny]==-1||cycid[nx][ny]==id); cycid[nx][ny]=id; }
			assert(cycpos[x][y][d]==-1||cycpos[x][y][d]==p-off[id]); cycpos[x][y][d]=p-off[id];
			d=(d+1)%4;
		}
		px[p]=x,py[p]=y,pd[p]=d;
		//printf("(%d,%d,%d)",x,y,d);
		if(d==4||nx==sx&&ny==sy) break;
		x=nx,y=ny,d=(d+3)%4;
	}
	//puts("");
	off[nid]=off[id]+len; return id;
}

void precalc() {
	nid=0,np=0; off[0]=0; memset(cycid,-1,sizeof(cycid)); memset(cycpos,-1,sizeof(cycpos)); memset(pid,-1,sizeof(pid));
	topid=createcyc(0,0,0);
	botid=createcyc(h-1,w-1,2);
	static int qx[MAXH*MAXW],qy[MAXH*MAXW],qhead,qtail; qhead=qtail=0; memset(reach,false,sizeof(reach)); qx[qhead]=0,qy[qhead]=0,++qhead,reach[0][0]=true;
	while(qtail<qhead) {
		int x=qx[qtail],y=qy[qtail]; ++qtail;
		REP(k,4) { int nx=x+DX[k],ny=y+DY[k]; if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]=='.'&&!reach[nx][ny]) qx[qhead]=nx,qy[qhead]=ny,++qhead,reach[nx][ny]=true; }
	}
	REP(x,h) REP(y,w) if(reach[x][y]) REP(k,4) { int nx=x+DX[k],ny=y+DY[k]; if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]!='.'&&cycid[nx][ny]==-1) createcyc(x,y,k); }
	REP(x,h) REP(y,w) if(g[x][y]=='.') { int id=pid[x][y]=nid++; int p=np++; px[p]=x,py[p]=y,pd[p]=4; off[nid]=off[id]+1; }

	//REP(id,nid) if(off[id+1]-off[id]>1) { printf("%d:",id); FOR(j,off[id],off[id+1]) printf(" (%d,%d,%d)",px[j],py[j],pd[j]); puts(""); }
	memset(nocc,0,sizeof(nocc)); REP(id,nid) FOR(j,off[id],off[id+1]) { int x=px[j],y=py[j],d=pd[j]; int o=nocc[x][y]++; occ[x][y][o]=id; occpos[x][y][o]=j-off[id]; }
	common.clear(); REP(x,h) REP(y,w) REP(i,nocc[x][y]) REP(j,nocc[x][y]) if(occ[x][y][i]<occ[x][y][j]) common.insert((ll)nid*occ[x][y][i]+occ[x][y][j]); common.erase((ll)nid*topid+botid); common.erase((ll)nid*botid+topid);
	//for(set<pair<int,int> >::iterator it=common.begin();it!=common.end();++it) { int a=it->first,b=it->second; if(off[a+1]-off[a]<=1||off[b+1]-off[b]<=1) continue; printf("%d-%d\n",a,b); }
}

int nb,bx[MAXB],by[MAXB];
int bcnt[2][MAXB];
int bseg[MAXB],bsegpos[MAXB];
int q[MAXB],qhead,qtail;

typedef struct Seg { int id,l,r,len; int ndir; int prv,nxt; } Seg;
int shead[2];
Seg seg[2+9*MAXB]; int segcnt;
void printseg(int s) {
	int id=seg[s].id; if(off[id+1]-off[id]<=1) FOR(j,off[id],off[id+1]) printf("[%d,%d]",px[j],py[j]); else printf("(%d,%d..%d=[%d,%d]..[%d,%d])",seg[s].id,seg[s].l,seg[s].r,px[off[seg[s].id]+seg[s].l],py[off[seg[s].id]+seg[s].l],px[off[seg[s].id]+seg[s].r],py[off[seg[s].id]+seg[s].r]);
}
void printsegchain(int s) {
	puts(""); while(s!=-1) { printf("\t%d:<%d,%d,%d|%d>",s,seg[s].prv,seg[s].nxt,seg[s].len,seg[s].ndir); printseg(s); puts(""); s=seg[s].nxt; } puts("");
}
int createseg(int id,int l,int r,int len,int ndir,int prv,int nxt) {
	int s=segcnt++; seg[s].id=id,seg[s].l=normpos(id,l),seg[s].r=normpos(id,r),seg[s].len=len;
	seg[s].ndir=ndir,seg[s].prv=prv,seg[s].nxt=nxt; return s;
}
void getsegp(int s,int pos,int &x,int &y,int &d) {
	while(pos<0) { assert(seg[s].prv!=-1); s=seg[s].prv; pos+=seg[s].len; }
	while(pos>=seg[s].len) { pos-=seg[s].len; assert(seg[s].nxt!=-1); s=seg[s].nxt; }
	getp(seg[s].id,normpos(seg[s].id,seg[s].l+pos),x,y,d); if(pos==seg[s].len-1) d=s[seg].ndir;
}
void splitseg(int s,int pos,int &pseg,int &nseg,int sd,int td) {
	assert(pos>=0&&pos<seg[s].len);
	nseg=createseg(seg[s].id,seg[s].l+pos+1,seg[s].r,seg[s].len-pos-1,seg[s].ndir,-1,seg[s].nxt); if(seg[nseg].nxt!=-1) seg[seg[nseg].nxt].prv=nseg;
	REP(i,nb) if(bseg[i]==s&&bsegpos[i]>pos) bseg[i]=nseg,bsegpos[i]-=pos+1;
	pseg=s; seg[s].r=normpos(seg[s].id,seg[s].l+pos-1); seg[s].len=pos; seg[s].ndir=4; seg[s].nxt=-1;
	if(seg[pseg].len==0) { assert(seg[pseg].prv!=-1); pseg=seg[pseg].prv; seg[pseg].ndir=4; seg[pseg].nxt=-1; }
	if(seg[nseg].len==0) { assert(seg[nseg].nxt!=-1); nseg=seg[nseg].nxt; seg[nseg].prv=-1; }
}
int sappend(int prv,int id,int l,int r,int len,int dir) {
	assert(prv!=-1); int s=createseg(id,l,r,len,4,prv,-1); seg[prv].ndir=dir; seg[prv].nxt=s; return s;
}
void mergeseg(int prv,int nxt,int dir) {
	seg[prv].nxt=nxt; seg[nxt].prv=prv; seg[prv].ndir=dir;
}
bool segupdate(int at,int s) {
	//printf("\t\tsegupdate(%d,%d)=",at,s); printseg(s); puts("");
	for(int ss=shead[1-at];ss!=-1;ss=seg[ss].nxt) {
		//printf("\t\t\ttesting e[%d][%d]\n",seg[s].id,seg[ss].id);
		int a=seg[s].id,b=seg[ss].id; if(a>b) swap(a,b);
		if(seg[s].id==seg[ss].id||common.count((ll)nid*a+b)) return false;
	}
	REP(i,nb) {
		int x=bx[i],y=by[i];
		REP(j,nocc[x][y]) if(occ[x][y][j]==seg[s].id) {
			int pos=occpos[x][y][j];
			if(seg[s].l<=seg[s].r&&(pos<seg[s].l||pos>seg[s].r)) continue;
			if(seg[s].l>seg[s].r&&seg[s].r<pos&&pos<seg[s].l) continue;
			//printf("\t\tfound block (%d,%d) in seg (%d,%d..%d) -> [%d,%d=>%d]\n",x,y,seg[s].id,seg[s].l,seg[s].r,s,pos-seg[s].l,normpos(seg[s].id,pos-seg[s].l));
			bcnt[at][i]++; bseg[i]=s; bsegpos[i]=normpos(seg[s].id,pos-seg[s].l);
			if(bcnt[at][i]==1) q[qhead++]=i;
			break;
		}
	}
	return true;
}

bool solve() {
	//printf("solving:"); REP(i,nb) printf(" (%d,%d)",bx[i],by[i]); puts("");
	qhead=qtail=0; segcnt=0; memset(bcnt,0,sizeof(bcnt));
	shead[0]=createseg(topid,0,off[topid+1]-off[topid]-1,off[topid+1]-off[topid],4,-1,-1);
	shead[1]=createseg(botid,0,off[botid+1]-off[botid]-1,off[botid+1]-off[botid],4,-1,-1);
	assert(segupdate(0,shead[0])); assert(segupdate(1,shead[1]));
	while(qtail<qhead) {
		int idx=q[qtail++];
		//printf("\tpath blocked by (%d,%d) [%d,%d]\n",bx[idx],by[idx],bseg[idx],bsegpos[idx]);
		assert(bcnt[0][idx]+bcnt[1][idx]>0);
		assert(bcnt[0][idx]==0||bcnt[1][idx]==0);
		int at=bcnt[0][idx]>0?0:1;
		if(bcnt[at][idx]!=1) continue;
		int sx,sy,sd,tx,ty,td; getsegp(bseg[idx],bsegpos[idx]-1,sx,sy,sd); getsegp(bseg[idx],bsegpos[idx]+1,tx,ty,td);
		//printf("\t(%d,%d,%d) / (%d,%d,%d)\n",sx,sy,sd,tx,ty,td);
		int pseg,nseg; splitseg(bseg[idx],bsegpos[idx],pseg,nseg,sd,td); int cseg=pseg;
		int cx=sx,cy=sy,cd=sd; //int tmp=0;
		while(true) {
			//printf("cx=%d cy=%d cd=%d\n",cx,cy,cd); if(++tmp>10) exit(0);
			if(cx==tx&&cy==ty) { mergeseg(cseg,nseg,4); break; }
			if(cx+DX[cd]==bx[idx]&&cy+DY[cd]==by[idx]) cd=(cd+1)%4;
			int nx=cx+DX[cd],ny=cy+DY[cd]; assert(nx>=0&&nx<h&&ny>=0&&ny<w);
			if(g[nx][ny]=='.') {
				if(nx==tx&&ny==ty) { mergeseg(cseg,nseg,cd); break; }
				cseg=sappend(cseg,pid[nx][ny],0,0,1,cd);
				cx=nx,cy=ny,cd=(cd+3)%4;
			} else {
				int id=cycid[nx][ny],spos=cycpos[cx][cy][cd],cpos=spos,len=off[id+1]-off[id]; assert(id!=-1&&cpos!=-1);
				//printf("\t\tid=%d spos=%d len=%d\n",id,spos,len);
				int nd; getp(id,cpos,nx,ny,nd); assert(nx==cx&&ny==cy);
				{
					int ax,ay,ad; getsegp(cseg,seg[cseg].len-2,ax,ay,ad);
					if(nd==(ad^2)) cd=4; else cd=nd,spos=normpos(id,spos+1),--len;
				}
				while(nx!=bx[idx]||ny!=by[idx]) {
					cpos=normpos(id,cpos-1); --len;
					getp(id,cpos,nx,ny,nd);
				}
				int tpos=normpos(id,cpos-1); --len;
				getp(id,tpos,nx,ny,nd);
				if(nx==tx&&ny==ty) {
					int bx,by,bd; getp(id,normpos(id,tpos-1),bx,by,bd);
					if(td==(bd^2)) nd=4; else nd=bd,tpos=normpos(id,tpos-1),--len;
					cseg=sappend(cseg,id,spos,tpos,len,cd);
					mergeseg(cseg,nseg,nd); break;
				}
				cseg=sappend(cseg,id,spos,tpos,len,cd);
				cx=nx,cy=ny,cd=(nd+1)%4;
			}
		}
		//REP(i,2) { printf("\t%s: ",i==0?"TOP":"BOT"); printsegchain(shead[i]); }
		for(cseg=seg[pseg].nxt;cseg!=nseg;cseg=seg[cseg].nxt) if(!segupdate(at,cseg)) return false;
	}
	return true;
}

void run() {
	scanf("%d%d%d",&h,&w,&nq);
	REP(x,h) scanf("%s",g[x]);
	bool dbg=h==50&&w==50&&(nq==0||nq==10000);
	if(dbg) {
		char a[]="..................................................";
		char b[]=".################################################.";
		char c[]=".#................................................";
		char d[]=".#.###############################################";
		char* pat[]={b,c,c,d,c,c};
		REP(x,h) {
			char* exp=(x==0||x==h-1)?a:pat[(x-1)%6];
			if(strcmp(g[x],exp)!=0) printf("%d: %s\n",x,g[x]);
		}
	}
	//h=MAXH; w=MAXW; REP(x,h) REP(y,w) g[x][y]=(x%2==1&&y%2==1&&(x!=h-1||y!=w-1))?'#':'.'; g[2][2]='#';
	precalc();
	//int mxocc=0; REP(x,h) REP(y,w) if(nocc[x][y]>mxocc) mxocc=nocc[x][y]; printf("nid=%d np=%d (%.9lf) mxocc=%d\n",nid,np,1.0*np/w/h,mxocc); exit(0);
	/*if(nq==0) {
		vector<pair<int,int> > all; REP(x,h) REP(y,w) if(g[x][y]=='.'&&(x!=0||y!=0)&&(x!=h-1||y!=w-1)) all.PB(MP(x,y));
		while(true) {
			nb=rand()%MAXB+1;
			REP(i,nb) {
				int idx=i+rand()%(SZ(all)-i);
				swap(all[i],all[idx]); bx[i]=all[i].first,by[i]=all[i].second;
			}
			//printf("%d\n",nb); REP(i,nb) printf("%d %d\n",bx[i]+1,by[i]+1);
			printf("%s\n",solve()?"YES":"NO"); fflush(stdout);
		}
	}*/
	REP(i,nq) {
		scanf("%d",&nb); REP(j,nb) scanf("%d%d",&bx[j],&by[j]),--bx[j],--by[j];
		printf("%s\n",solve()?"YES":"NO"); fflush(stdout);
	}
}

int main() {
	run();
	return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=1000;
const int MAXW=1000;
const int MAXB=10;
const int MAXSEG=2+9*MAXB;
const int MAXC=2*MAXH*MAXW+2;
const int MAXFREQ=5;
const int MAXP=MAXFREQ*MAXH*MAXW;
const int DX[]={-1,0,+1,0},DY[]={0,+1,0,-1};

int h,w,nq;
char g[MAXH][MAXW+1];
int ncyc;
int clen[MAXC];
int coff[MAXC+1];
int np;
int px[MAXP],py[MAXP],pd[MAXP];
int pcyc[MAXH][MAXW][MAXFREQ],pcycidx[MAXH][MAXW][MAXFREQ],pcyccnt[MAXH][MAXW];
int topcyc,botcyc;
int xycyc[MAXH][MAXW];
int xydcyc[MAXH][MAXW][4],xydcycidx[MAXH][MAXW][4];
set<ll> common;

int normidx(int c,int idx) { while(idx<0) idx+=clen[c]; while(idx>=clen[c]) idx-=clen[c]; return idx; }
int getcycx(int c,int idx) { return px[coff[c]+idx]; }
int getcycy(int c,int idx) { return py[coff[c]+idx]; }
int getcycd(int c,int idx) { return pd[coff[c]+idx]; }

int createcyc(int sx,int sy,int sd) {
	//printf("createcyc(%d,%d,%d)\n\t",sx,sy,sd);
	int x=sx,y=sy,d=sd,c=ncyc++; clen[c]=0;
	while(true) {
		int p=np++; ++clen[c]; int nx,ny;
		if(sx==0&&sy==0&&sd==0&&x==h-1&&y==w-1&&d==1) d=4;
		if(sx==h-1&&sy==w-1&&sd==2&&x==0&&y==0&&d==3) d=4;
		while(d!=4) {
			nx=x+DX[d],ny=y+DY[d];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]=='.') break;
			assert(xydcyc[x][y][d]==-1); xydcyc[x][y][d]=c; xydcycidx[x][y][d]=p-coff[c];
			d=(d+1)%4;
		}
		px[p]=x,py[p]=y,pd[p]=d;
		//printf("(%d,%d,%d)",x,y,d);
		if(d==4||nx==sx&&ny==sy) break;
		x=nx,y=ny,d=(d+3)%4;
	}
	//puts("");
	coff[ncyc]=coff[c]+clen[c]; return c;
}
void precalc() {
	ncyc=0,np=0; coff[0]=0; memset(xydcyc,-1,sizeof(xydcyc)); memset(xydcycidx,-1,sizeof(xydcycidx)); memset(xycyc,-1,sizeof(xycyc));
	topcyc=createcyc(0,0,0);
	botcyc=createcyc(h-1,w-1,2);
	static int qx[MAXH*MAXW],qy[MAXH*MAXW],qhead,qtail; static bool reach[MAXH][MAXW]; qhead=qtail=0; memset(reach,false,sizeof(reach)); qx[qhead]=0,qy[qhead]=0,++qhead,reach[0][0]=true;
	while(qtail<qhead) {
		int x=qx[qtail],y=qy[qtail]; ++qtail;
		REP(k,4) { int nx=x+DX[k],ny=y+DY[k]; if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]=='.'&&!reach[nx][ny]) qx[qhead]=nx,qy[qhead]=ny,++qhead,reach[nx][ny]=true; }
	}
	REP(x,h) REP(y,w) if(reach[x][y]) REP(k,4) { int nx=x+DX[k],ny=y+DY[k]; if(0<=nx&&nx<h&&0<=ny&&ny<w&&g[nx][ny]!='.'&&xydcyc[x][y][k]==-1) createcyc(x,y,k); }
	REP(x,h) REP(y,w) if(g[x][y]=='.') { int c=xycyc[x][y]=ncyc++; int p=np++; px[p]=x,py[p]=y,pd[p]=4; clen[c]=1; coff[ncyc]=coff[c]+clen[c]; }

	//REP(c,ncyc) if(clen[c]>1) { printf("%d:",c); FOR(j,coff[c],coff[c+1]) printf(" (%d,%d,%d)",px[j],py[j],pd[j]); puts(""); }
	memset(pcyccnt,0,sizeof(pcyccnt)); REP(c,ncyc) FOR(j,coff[c],coff[c+1]) { int x=px[j],y=py[j],d=pd[j]; int i=pcyccnt[x][y]++; pcyc[x][y][i]=c; pcycidx[x][y][i]=j-coff[c]; }
	common.clear(); REP(x,h) REP(y,w) REP(i,pcyccnt[x][y]) REP(j,pcyccnt[x][y]) if(pcyc[x][y][i]<pcyc[x][y][j]) common.insert((ll)ncyc*pcyc[x][y][i]+pcyc[x][y][j]); common.erase((ll)ncyc*topcyc+botcyc); common.erase((ll)ncyc*botcyc+topcyc);
	//for(set<pair<int,int> >::iterator it=common.begin();it!=common.end();++it) { int a=it->first,b=it->second; if(off[a+1]-off[a]<=1||off[b+1]-off[b]<=1) continue; printf("%d-%d\n",a,b); }
}

typedef struct Seg { int cyc,l,r,len,nd,prv,nxt; } Seg;

int nb;
int bx[MAXB],by[MAXB];
int bcnt[MAXB],bat[MAXB],bseg[MAXB],bpos[MAXB];
int q[4*MAXB],qhead,qtail;

int shead[2];
Seg seg[MAXSEG]; int scnt;

void printpath(int s) {
	while(seg[s].prv!=-1) s=seg[s].prv;
	for(;s!=-1;s=seg[s].nxt) {
		printf("\t\t[%d,%d]",getcycx(seg[s].cyc,seg[s].l),getcycy(seg[s].cyc,seg[s].l)); if(seg[s].l!=seg[s].r) printf("-[%d,%d]",getcycx(seg[s].cyc,seg[s].r),getcycy(seg[s].cyc,seg[s].r));
		printf("<%d-%d-%d>(%d)\n",seg[s].prv,s,seg[s].nxt,seg[s].len);
	}
}
int createseg(int cyc,int l,int r,int len,int nd) { seg[scnt].cyc=cyc,seg[scnt].l=l,seg[scnt].r=r,seg[scnt].len=len,seg[scnt].nd=nd,seg[scnt].prv=seg[scnt].nxt=-1; return scnt++; }
bool xyoncyc(int x,int y,int i,int c) {
	return pcyc[x][y][i]==c;
}
int getxycycpos(int x,int y,int i,int c) {
	return pcycidx[x][y][i];
}
bool xyonseg(int x,int y,int i,int s) {
	if(pcyc[x][y][i]==seg[s].cyc) {
		int idx=pcycidx[x][y][i];
		if(seg[s].l<=seg[s].r&&seg[s].l<=idx&&idx<=seg[s].r) return true;
		if(seg[s].l>seg[s].r&&(idx<=seg[s].r||idx>=seg[s].l)) return true;
	}
	return false;
}
int getxysegpos(int x,int y,int i,int s) {
	if(pcyc[x][y][i]==seg[s].cyc) {
		int idx=pcycidx[x][y][i];
		if(seg[s].l<=seg[s].r&&seg[s].l<=idx&&idx<=seg[s].r) return idx-seg[s].l;
		if(seg[s].l>seg[s].r&&(idx<=seg[s].r||idx>=seg[s].l)) return idx-seg[s].l+(idx<=seg[s].r?clen[seg[s].cyc]:0);
	}
	assert(false); return -1;
}
bool bonseg(int b,int i,int s) { return xyonseg(bx[b],by[b],i,s); }
bool banyonseg(int b,int s) {
	REP(j,pcyccnt[bx[b]][by[b]]) if(bonseg(b,j,s)) return true;
	return false;
}
int getbsegpos(int b,int i,int s) { return getxysegpos(bx[b],by[b],i,s); }
int getonlybsegpos(int b,int s) {
	int ret=-1; REP(j,pcyccnt[bx[b]][by[b]]) if(bonseg(b,j,s)) { assert(ret==-1); ret=getbsegpos(b,j,s); } assert(ret!=-1); return ret;
}
int findnxtcycpos(int c,int idx,int x,int y) {
	int ret=-1;
	//printf("findnxtcycpos(%d,%d,%d,%d)\n",c,idx,x,y);
	REP(j,pcyccnt[x][y]) if(xyoncyc(x,y,j,c)) {
		int cur=getxycycpos(x,y,j,c); //printf("\t%d\n",cur);
		if(ret==-1||(ret>=idx&&cur>=idx&&cur<ret||ret<idx&&(cur>=idx||cur<ret))) ret=cur;
	}
	assert(ret!=-1); return ret;
}
void getsegxyd(int s,int pos,int &x,int &y,int &d) {
	int idx=normidx(seg[s].cyc,seg[s].l+pos);
	x=getcycx(seg[s].cyc,idx),y=getcycy(seg[s].cyc,idx),d=pos==seg[s].len-1?seg[s].nd:getcycd(seg[s].cyc,idx);
}
void ssplit(int s,int pos,int &pseg,int &nseg) {
	while(pos<=0) { assert(seg[s].prv!=-1); s=seg[s].prv; pos+=seg[s].len; }
	while(pos>seg[s].len) { assert(seg[s].nxt!=-1); pos-=seg[s].len; s=seg[s].nxt; }
	if(pos==seg[s].len) { assert(seg[s].nxt!=-1); pseg=s,nseg=seg[s].nxt; seg[pseg].nxt=seg[nseg].prv=-1; return; }
	int nr=normidx(seg[s].cyc,seg[s].l+pos-1),nl=normidx(seg[s].cyc,seg[s].l+pos);
	nseg=createseg(seg[s].cyc,nl,seg[s].r,seg[s].len-pos,seg[s].nd); seg[nseg].nxt=seg[s].nxt; if(seg[nseg].nxt!=-1) seg[seg[nseg].nxt].prv=nseg;
	pseg=s,seg[pseg].r=nr,seg[pseg].len=pos,seg[pseg].nd=getcycd(seg[s].cyc,nr);
	seg[pseg].nxt=-1,seg[nseg].prv=-1;
	REP(i,nb) if(bcnt[i]==1&&bseg[i]==pseg&&bpos[i]>=pos) bseg[i]=nseg,bpos[i]-=pos;
}
void smerge(int pseg,int d,int nseg) {
	seg[pseg].nxt=nseg; seg[pseg].nd=d; seg[nseg].prv=pseg;
}
void sadd(int at,int nseg) {
	//printf("sadd(%d,%d)\n",at,nseg);
	REP(i,nb) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,nseg)) {
		int pos=getbsegpos(i,j,nseg);
		++bcnt[i],bat[i]=at,bseg[i]=nseg,bpos[i]=pos,q[qhead++]=i;
		//printf("\t\tadding (%d,%d) on (%d,%d) [%d]\n",bx[i],by[i],bseg[i],bpos[i],bat[i]);
		assert(bcnt[i]==1);
	}
}
void sremove(int s) {
	while(seg[s].prv!=-1) s=seg[s].prv;
	while(s!=-1) {
		REP(i,nb) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
			--bcnt[i];
			//printf("\t\tremoving (%d,%d)\n",bx[i],by[i]);
			assert(bcnt[i]==0);
		}
		s=seg[s].nxt;
	}
}
bool intersectspath(int s,int at) {
	for(int ss=shead[at];ss!=-1;ss=seg[ss].nxt) {
		int a=seg[s].cyc,b=seg[ss].cyc;
		if(a>b) swap(a,b);
		if(a==b||common.count((ll)a*ncyc+b)) return true;
	}
	return false;
}
void fixprefix(int &lst,int &d,int &s) {
	REP(i,nb) if(bcnt[i]>0) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
		int ss=lst; while(ss!=-1&&!banyonseg(i,ss)) ss=seg[ss].prv; if(ss==-1) continue;
		int spos=getbsegpos(i,j,s),sspos=getonlybsegpos(i,ss);
		int ss1,ss2; ssplit(ss,sspos,ss1,ss2); lst=ss1; d=seg[ss1].nd; sremove(ss2);
		if(spos!=0) { int s1,s2; ssplit(s,spos,s1,s2); s=s2; }
	}
}
bool fixsuffix(int &s,int &d,int &fst) {
	bool ret=false;
	REP(i,nb) if(bcnt[i]>0) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
		int ss=fst; while(ss!=-1&&!banyonseg(i,ss)) ss=seg[ss].nxt; if(ss==-1) continue;
		int spos=getbsegpos(i,j,s),sspos=getonlybsegpos(i,ss);
		int ss1,ss2; ssplit(ss,sspos+1,ss1,ss2); fst=ss2; d=seg[ss1].nd; sremove(ss1);
		if(spos!=seg[s].len-1) { int s1,s2; ssplit(s,spos+1,s1,s2); s=s1; }
		ret=true;
	}
	if(ret) return ret;
	int vx=getcycx(seg[s].cyc,seg[s].r),vy=getcycy(seg[s].cyc,seg[s].r),wx=getcycx(seg[fst].cyc,seg[fst].l),wy=getcycy(seg[fst].cyc,seg[fst].l);
	//printf("fixsuffix -> (%d,%d) / (%d,%d) [%d:%d,%d]\n",vx,vy,wx,wy,s,seg[s].cyc,seg[s].r);
	if(vx==wx&&vy==wy) {
		int ss=fst,ss1,ss2; ssplit(ss,1,ss1,ss2); fst=ss2; d=seg[ss1].nd; sremove(ss1);
		ret=true;
	}
	return ret;
}

void fixinternal(int &s) {
	int mn[MAXB],mx[MAXB]; REP(i,nb) mn[i]=mx[i]=-1;
	REP(i,nb) REP(j,pcyccnt[bx[i]][by[i]]) if(bonseg(i,j,s)) {
		int cur=getbsegpos(i,j,s);
		if(mn[i]==-1||cur<mn[i]) mn[i]=cur;
		if(mx[i]==-1||cur>mx[i]) mx[i]=cur;
	}
	while(true) {
		//REP(i,nb) if(mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]) printf("%d: %d..%d\n",i,mn[i],mx[i]);
		int bidx=-1; REP(i,nb) if(mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]&&(bidx==-1||mx[i]>mx[bidx])) bidx=i; /*printf("=>%d\n",bidx);*/ if(bidx==-1) return;
		REP(i,nb) if(mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]) assert(mn[bidx]<=mn[i]&&mx[i]<=mx[bidx]||mx[i]<mn[bidx]);
		if(mn[bidx]==0) {
			int s3,s4; ssplit(s,mx[bidx]-mn[bidx],s3,s4);
			//printpath(s3); puts(""); printpath(s4); puts("");
			s=s4;
		} else {
			int s1,s2; ssplit(s,mn[bidx],s1,s2); int s3,s4; ssplit(s2,mx[bidx]-mn[bidx],s3,s4);
			//printpath(s1); puts(""); printpath(s2); puts(""); printpath(s3); puts(""); printpath(s4); puts("");
			smerge(s1,seg[s1].nd,s4); s=s1;
		}
		REP(i,nb) if(i!=bidx&&mn[i]!=-1&&mx[i]!=-1&&mn[i]!=mx[i]&&mx[i]>=mn[bidx]) mn[i]=mx[i]=-1; mn[bidx]=mx[bidx]=-1;
	}
}

bool solve() {
	// two paths of segments
	// invariant: the two paths do not intersect
	// invariant: each blocked node occurs on at most one segment
	qhead=qtail=scnt=0; memset(bcnt,0,sizeof(bcnt));
	shead[0]=createseg(topcyc,0,clen[topcyc]-1,clen[topcyc],4); sadd(0,shead[0]);
	shead[1]=createseg(botcyc,0,clen[botcyc]-1,clen[botcyc],4); sadd(1,shead[1]);
	while(qtail<qhead) {
		int bidx=q[qtail++],at=bat[bidx];
		if(bcnt[bidx]!=1) continue;
		//printf("processing (%d,%d) on (%d,%d) [%d]\n",bx[bidx],by[bidx],bseg[bidx],bpos[bidx],bat[bidx]); printpath(bseg[bidx]); puts("");
		int sseg,pseg,qseg,tseg; ssplit(bseg[bidx],bpos[bidx],sseg,pseg); ssplit(pseg,1,qseg,tseg); sremove(qseg); //printpath(sseg); puts(""); printpath(tseg); puts("");
		int sx,sy,sd; getsegxyd(sseg,seg[sseg].len-1,sx,sy,sd);
		int tx,ty,td; getsegxyd(tseg,0,tx,ty,td);
		//printf("(%d,%d)-(%d,%d)\n",sx,sy,tx,ty);
		int cseg=sseg,cx=sx,cy=sy,cd=sd;
		if(sx==tx&&sy==ty) {
			int s1,s2; ssplit(tseg,1,s1,s2); sremove(s1); smerge(sseg,seg[s1].nd,s2);
		} else while(true) {
			if(cx+DX[cd]==bx[bidx]&&cy+DY[cd]==by[bidx]) cd=(cd+1)%4;
			//printf("\t(%d,%d)+%d->(%d,%d)\n",cx,cy,cd,cx+DX[cd],cy+DY[cd]);
			int vx=cx+DX[cd],vy=cy+DY[cd]; assert(vx>=0&&vx<h&&vy>=0&&vy<w);
			int wx,wy,wd,nseg;
			if(g[vx][vy]=='.') {
				//printf("\t\tempty\n");
				wx=vx,wy=vy,wd=(cd+3)%4;
				nseg=createseg(xycyc[vx][vy],0,0,1,wd);
			} else {
				//printf("\t\tfull\n");
				int c=xydcyc[cx][cy][cd],idx=xydcycidx[cx][cy][cd]; assert(c!=-1&&idx!=-1&&getcycx(c,idx)==cx&&getcycy(c,idx)==cy);
				cd=getcycd(c,idx); int sidx=normidx(c,idx+1);
				int tidx=findnxtcycpos(c,sidx,bx[bidx],by[bidx]); tidx=normidx(c,tidx-1);
				vx=getcycx(c,sidx),vy=getcycy(c,sidx),wx=getcycx(c,tidx),wy=getcycy(c,tidx),wd=getcycd(c,tidx);
				int len=tidx-sidx+1; if(len<=0) len+=clen[c];
				nseg=createseg(c,sidx,tidx,len,wd); // nseg=segment starting at (vx,vy) and ending at (wx,wy) with direction wd such that wx+DX[wd]==bx[bidx] && wy+DY[wd]==by[bidx]
				//printf("\t\t[%d,%d]->[%d,%d]+%d <%d>\n",vx,vy,wx,wy,wd,c);
			}
			if(intersectspath(nseg,1-at)) return false;
			fixprefix(cseg,cd,nseg);
			bool done=fixsuffix(nseg,wd,tseg);
			fixinternal(nseg);
			//printf("final: (at=%d)\n",at); printpath(nseg); puts("");
			for(int s=nseg;s!=-1;s=seg[s].nxt) sadd(at,s);
			smerge(cseg,cd,nseg);
			//printf("becoming: (at=%d)\n",at); printpath(nseg); puts("");
			while(seg[nseg].nxt!=-1) nseg=seg[nseg].nxt;
			if(done) { smerge(nseg,wd,tseg); break; }
			cseg=nseg,cx=wx,cy=wy,cd=wd;
		}
		//REP(i,2) { printf("\t%s:\n",i==0?"TOP":"BOTTOM"); printpath(shead[i]); }
	}
	return true;
}

void run() {
	scanf("%d%d%d",&h,&w,&nq);
	REP(x,h) scanf("%s",g[x]);
	if(h==17&&w==30) FOR(x,15,h) printf("%s\n",g[x]);
	precalc();
	REP(i,nq) {
		scanf("%d",&nb); REP(j,nb) scanf("%d%d",&bx[j],&by[j]),--bx[j],--by[j];
		bool have=solve();
		printf("%s\n",have?"YES":"NO"); fflush(stdout);
	}
}

int main() {
	run();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int dx[]={-1,-1,-1,0,0,1,1,1};
const int dy[]={-1,0,1,-1,1,-1,0,1};
const int N=1005,M=1010000;
int n,m,Q,nd,id[N][N];
int fa[M],flg[M];
int vis[M],axib[M],T;
vector<int> e[M];
set<int> S[M],adj[N][N];
char s[N][N];
void init(int x){
	if (vis[x]==T) return;
	vis[x]=T; e[x].resize(0);
}
void add_edge(int x,int y){
	init(x); init(y);
	e[x].PB(y); e[y].PB(x);
}
void bfs(int S,int *q){
	axib[S]=++*axib;
	int h=0,t=1; q[1]=S;
	while (h!=t){
		int x=q[++h];
		for (auto i:e[x])
			if (axib[i]!=*axib){
				q[++t]=i;
				axib[i]=*axib;
			}
	}
	*q=t;
}
int get(int x){
	return x==fa[x]?x:fa[x]=get(fa[x]);
}
int main(){
	scanf("%d%d%d",&n,&m,&Q);
	For(i,0,n+1) For(j,0,m+1) s[i][j]='#';
	For(i,1,n) scanf("%s",s[i]+1);
	For(i,1,n) s[i][m+1]='#';
	For(i,0,1) For(j,0,1) s[i][j]=s[i+n][j+m]='.';
	For(i,0,n+1) For(j,0,m+1) id[i][j]=++nd,fa[nd]=nd;
	For(i,0,n+1) For(j,0,m+1) For(d,0,7){
		if (s[i][j]!='#') continue;
		int ni=i+dx[d],nj=j+dy[d];
		if (i<0||i>n+1||j<0||j>m+1||s[ni][nj]!='#') continue;
		fa[get(id[i][j])]=get(id[ni][nj]);
	}
	//For(i,0,n+1)
	//	printf("%s\n",s[i]);
	int SS=get(id[0][m+1]);
	int TT=get(id[n+1][0]);
	assert(SS!=TT);
	For(i,1,n) For(j,1,m){
		set<int> &tmp=adj[i][j];
		if (s[i][j]=='#'||(i==1&&j==1)||(i==n&&j==m)) continue;
		For(d,0,7){
			int ni=i+dx[d],nj=j+dy[d];
			if (i<0||i>n+1||j<0||j>m+1||s[ni][nj]!='#') continue;
			tmp.insert(get(id[ni][nj]));
		}
		for (auto p1:tmp) for (auto p2:tmp){
			assert(p1!=SS||p2!=TT);
			if (p1!=p2) S[p1].insert(p2);
		}
		//cout<<i<<' '<<j<<' '<<adj[i][j].size()<<endl;
	}
	while (Q--){
		++T;
		int k,X[15],Y[15];
		scanf("%d",&k);
		For(i,1,k){
			int x,y;
			scanf("%d%d",&x,&y);
			s[X[i]=x][Y[i]=y]='#';
			For(d,0,7){
				int nx=x+dx[d],ny=y+dy[d];
				if (nx<0||nx>n+1||ny<0||ny>m+1) continue;
				if (s[nx][ny]=='#')
					add_edge(get(id[x][y]),get(id[nx][ny]));
				else{
					for (auto k:adj[nx][ny]){
						S[k].insert(id[x][y]);
						S[id[x][y]].insert(k);
					}
					adj[nx][ny].insert(id[x][y]);
				}
			}
		}
		static int qs[105],qt[105];
		init(SS); init(TT);
		bfs(SS,qs); bfs(TT,qt);
		bool flag=0;
		For(i,1,*qs) if (qs[i]==TT) flag=1;
		For(i,1,*qs) For(j,1,*qt)
			if (S[qs[i]].find(qt[j])!=S[qs[i]].end())
				flag=1;
		puts(flag?"NO":"YES");
		fflush(stdout);
		For(i,1,k){
			int x=X[i],y=Y[i];
			s[X[i]][Y[i]]='.';
			For(d,0,7){
				int nx=x+dx[d],ny=y+dy[d];
				if (nx<0||nx>n+1||ny<0||ny>m+1) continue;
				if (s[nx][ny]=='#');
				else{
					for (auto k:adj[nx][ny]){
						S[k].erase(id[x][y]);
						S[id[x][y]].erase(k);
					}
					adj[nx][ny].erase(id[x][y]);
				}
			}
		}
	}
}


#include <bits/stdc++.h>
#define fe first
#define se second

using namespace std;

const int maxn = 1005;

vector< pair<int,int> > block;
set< pair<int,int> > sav;
bool fal[maxn][maxn];
int bel[maxn][maxn],h,w,q,cnt;

bool ok(int x,int y)
{
	return x >= 0 && y >= 0 && x <= h + 1 && y <= w + 1;
}

void dfs(int x,int y)
{
	if (!ok(x,y) || bel[x][y] || !fal[x][y]) return;
	bel[x][y] = cnt;
	for(int i = -1;i < 2;i ++)
		for(int j = -1;j < 2;j ++) dfs(x + i,y + j);
}

vector<int> imp;
int vis[maxn * maxn],fa[maxn * maxn],vistag,side_a,side_b;

void push(int u)
{
	if (vis[u] == vistag) return;
	vis[u] = vistag;
	fa[u] = u;
	imp.push_back(u);
}

int get(int u)
{
	return fa[u] == u ? u : fa[u] = get(fa[u]);
}

void merge(int u,int v)
{
	push(u),push(v);
	fa[get(u)] = get(v);
}

bool con(int u,int v)
{
	push(u),push(v);
	return get(u) == get(v);
}

bool new_point_cut()
{
	for(auto p : imp) if (con(p,side_a))
		for(auto q : imp) if (con(q,side_b))
			if (sav.find({p,q}) != sav.end()) return 1;
	return 0;
}

bool cut()
{
	++ vistag;imp.clear();
	push(side_a),push(side_b);
	for(auto p : block) bel[p.fe][p.se] = ++ cnt;
	for(auto p : block)
		for(int x = p.fe - 1;x < p.fe + 2;x ++)
			for(int y = p.se - 1;y < p.se + 2;y ++)
				if (ok(x,y) && bel[x][y] && bel[x][y] != bel[p.fe][p.se]) merge(bel[x][y],bel[p.fe][p.se]);
	if (new_point_cut() || con(side_a,side_b)) return 1;
	for(auto p : block)
		for(int x = p.fe - 2;x < p.fe + 3;x ++)
			for(int y = p.se - 2;y < p.se + 3;y ++)
				if (ok(x,y) && bel[x][y])
				{
					int u = bel[p.fe][p.se],v = bel[x][y];
					if (con(u,side_a) && con(side_b,v) || con(u,side_b) && con(v,side_a)) return 1;
				}
	return 0;
}

int main()
{
#ifdef LOCAL
	freopen("data.in","r",stdin),freopen("data.out","w",stdout);
#endif
	scanf("%d%d%d", &h, &w, &q);
	for(int i = 0;i <= h + 1;i ++) fal[i][0] = fal[i][w + 1] = 1;
	for(int i = 1;i <= w + 1;i ++) fal[0][i] = fal[h + 1][i] = 1;
	fal[0][0] = fal[0][1] = fal[1][0] = 0;
	fal[h + 1][w + 1] = fal[h + 1][w] = fal[h][w + 1] = 0;
	for(int i = 1;i <= h;i ++)
	{
		static char s[maxn];
		scanf("%s", s + 1);
		for(int j = 1;j <= w;j ++)
			fal[i][j] = (s[j] == '#');
	}
	for(int i = 0;i <= h + 1;i ++)
		for(int j = 0;j <= w + 1;j ++)
			if (fal[i][j] && !bel[i][j]) ++ cnt,dfs(i,j);
	side_a = bel[0][2],side_b = bel[2][0];
	for(int i = 0;i <= h + 1;i ++)
		for(int j = 0;j <= w + 1;j ++)
			if (bel[i][j])
				for(int x = i - 2;x < i + 3;x ++)
					for(int y = j - 2;y < j + 3;y ++)
					{
						if (i == 0 && j == 2 && x == 2 && y == 0) continue;
						if (i == 2 && j == 0 && x == 0 && y == 2) continue;
						if (i == h - 1 && j == w + 1 && x == h + 1 && y == w - 1) continue;
						if (i == h + 1 && j == w - 1 && x == h - 1 && y == w + 1) continue;
						if (ok(x,y) && bel[x][y] && bel[x][y] != bel[i][j])
							sav.insert({bel[i][j],bel[x][y]});
					}
	for(int i = 1;i <= q;i ++)
	{
		int c;
		scanf("%d", &c);
		block.resize(c);
		for(int j = 0;j < c;j ++)
			scanf("%d%d", &block[j].fe, &block[j].se);
		int pcnt = cnt;
		printf("%s\n", cut() ? "NO" : "YES");
		fflush(stdout);
		cnt = pcnt;
		for(int j  = 0;j < c;j ++)
			bel[block[j].fe][block[j].se] = 0;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define U 1006
#define N 1000012
#define H 5311031
#define ULL unsigned long long
#define MK make_pair
int xr=1124971;
inline int R(){xr=(1ll*(xr^1297131)*182791+12987941)%1000000007;return xr;}
int n,m,Q,K,tot=0,S,T,a[U][U],h[N],cnt=0,h1[H],cn1=0,f[U],cn=0,c[U<<3],num;bool vi[N];ULL w1[N];char sc[1012];
struct Edge{int to,next;}e[N*6];
struct Ed{pair<int,int>to;int next;}e1[N*6];
inline void AddEdge(int x,int y){e[++cnt]=(Edge){y,h[x]};h[x]=cnt;e[++cnt]=(Edge){x,h[y]};h[y]=cnt;}
inline void Add(int x,int y)
{
	if(!vi[x])c[++num]=x,vi[x]=1;e[++cnt]=(Edge){y,h[x]};h[x]=cnt;
	if(!vi[y])c[++num]=y,vi[y]=1;e[++cnt]=(Edge){x,h[y]};h[y]=cnt;
}
void dfs(int x){f[x]=cn;int i,y;for(i=h[x];i;i=e[i].next)if(!f[y=e[i].to])dfs(y);}
struct has{
	inline void Ins(ULL x,pair<int,int>p){int v=x%H,i;for(i=h1[v];i;i=e1[i].next)if(e1[i].to==p)return;e1[++cn1]=(Ed){p,h1[v]};h1[v]=cn1;}
	inline bool Fin(ULL x,pair<int,int>p){int v=x%H,i;for(i=h1[v];i;i=e1[i].next)if(e1[i].to==p)return true;return false;}
}ha;
int tm[12],nu,A[127],t1,B[127],t2;bool vis[N];
void dfs1(int x,int *V,int &sz){vis[V[++sz]=x]=1;int i,y;for(i=h[x];i;i=e[i].next)if(!vis[y=e[i].to])dfs1(y,V,sz);}
int main(){
	scanf("%d%d%d",&n,&m,&Q);S=++tot;T=++tot;int i,j,k,w,x,y;bool fl;for(i=1;i<n;i++)for(j=1;j<m;j++)a[i][j]=++tot;
	for(i=0;i<=n;i++)a[i][0]=S,a[i][m]=T;for(i=0;i<=m;i++)a[0][i]=T,a[n][i]=S;
	for(i=1;i<=n;i++)
	{
		scanf("%s",sc+1);
		for(j=1;j<=m;j++)if(sc[j]=='#')AddEdge(a[i][j],a[i-1][j]),AddEdge(a[i][j],a[i][j-1]),AddEdge(a[i][j],a[i-1][j-1]);
	}
	for(i=1;i<=tot;i++)if(!f[i])w1[++cn]=1ull*R()*R()*R(),dfs(i);
	for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
	{
		if(((i==1)&&(j==1))||((i==n)&&(j==m)))continue;
		nu=0;tm[++nu]=f[a[i-1][j-1]];tm[++nu]=f[a[i-1][j]];tm[++nu]=f[a[i][j-1]];tm[++nu]=f[a[i][j]];
		for(k=1;k<=nu;k++)for(w=1;w<=nu;w++)if(tm[k]<tm[w])ha.Ins(w1[tm[k]]^w1[tm[w]],MK(tm[k],tm[w]));
	}
	memset(h,0,sizeof(h));cnt=0;
	while(Q--)
	{
		scanf("%d",&K);
		while(K--){scanf("%d%d",&x,&y);Add(f[a[x][y]],f[a[x-1][y]]),Add(f[a[x][y]],f[a[x][y-1]]),Add(f[a[x][y]],f[a[x-1][y-1]]);}
		fl=true;t1=t2=0;dfs1(f[S],A,t1);if(vis[f[T]])fl=false;if(fl)dfs1(f[T],B,t2);
		for(i=1;(i<=t1)&&fl;i++)for(j=1;(j<=t2)&&fl;j++)if(ha.Fin(w1[A[i]]^w1[B[j]],MK(min(A[i],B[j]),max(A[i],B[j]))))fl=false;
		printf("%s\n",fl?"YES":"NO");fflush(stdout);for(i=1;i<=num;i++)x=c[i],vi[x]=vis[x]=0,h[x]=0;cnt=0;num=0;vis[f[S]]=vis[f[T]]=0;
	}return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>

#include<set>
using namespace std;
#define U 1006
#define N 1000012
#define H 5311031
#define ULL unsigned long long
#define MK make_pair
int xr=1124971;
inline int R(){xr=(1ll*(xr^1297131)*182791+12987941)%1000000007;return xr;}
int n,m,Q,K,tot=0,S,T,a[U][U],h[N],cnt=0,h1[H],cn1=0,f[U],cn=0,c[U<<3],num;bool vi[N];ULL w1[N];char sc[1012];
struct Edge{int to,next;}e[N*6];
struct Ed{pair<int,int>to;int next;}e1[N*6];
inline void AddEdge(int x,int y){e[++cnt]=(Edge){y,h[x]};h[x]=cnt;e[++cnt]=(Edge){x,h[y]};h[y]=cnt;}
inline void Add(int x,int y)
{
	if(!vi[x])c[++num]=x,vi[x]=1;e[++cnt]=(Edge){y,h[x]};h[x]=cnt;
	if(!vi[y])c[++num]=y,vi[y]=1;e[++cnt]=(Edge){x,h[y]};h[y]=cnt;
}
void dfs(int x){f[x]=cn;int i,y;for(i=h[x];i;i=e[i].next)if(!f[y=e[i].to])dfs(y);}
struct has{
	inline void Ins(ULL x,pair<int,int>p){int v=x%H,i;for(i=h1[v];i;i=e1[i].next)if(e1[i].to==p)return;e1[++cn1]=(Ed){p,h1[v]};h1[v]=cn1;}
	inline bool Fin(ULL x,pair<int,int>p){int v=x%H,i;for(i=h1[v];i;i=e1[i].next)if(e1[i].to==p)return true;return false;}
}ha;
set<pair<int,int> >st;
int tm[12],nu,A[127],t1,B[127],t2;bool vis[N];
void dfs1(int x,int *V,int &sz){vis[V[++sz]=x]=1;int i,y;for(i=h[x];i;i=e[i].next)if(!vis[y=e[i].to])dfs1(y,V,sz);}
int main(){
	scanf("%d%d%d",&n,&m,&Q);S=++tot;T=++tot;int i,j,k,w,x,y;bool fl;for(i=1;i<n;i++)for(j=1;j<m;j++)a[i][j]=++tot;
	for(i=0;i<=n;i++)a[i][0]=S,a[i][m]=T;for(i=0;i<=m;i++)a[0][i]=T,a[n][i]=S;
	for(i=1;i<=n;i++)
	{
		scanf("%s",sc+1);
		for(j=1;j<=m;j++)if(sc[j]=='#')AddEdge(a[i][j],a[i-1][j]),AddEdge(a[i][j],a[i][j-1]),AddEdge(a[i][j],a[i-1][j-1]);
	}
	for(i=1;i<=tot;i++)if(!f[i])w1[++cn]=1ull*R()*R()*R(),dfs(i);
	for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
	{
		if(((i==1)&&(j==1))||((i==n)&&(j==m)))continue;
		nu=0;tm[++nu]=f[a[i-1][j-1]];tm[++nu]=f[a[i-1][j]];tm[++nu]=f[a[i][j-1]];tm[++nu]=f[a[i][j]];
		for(k=1;k<=nu;k++)for(w=1;w<=nu;w++)if(tm[k]<tm[w])st.insert(MK(tm[k],tm[w]));//ha.Ins(w1[tm[k]]^w1[tm[w]],MK(tm[k],tm[w]));
	}
	memset(h,0,sizeof(h));cnt=0;
	while(Q--)
	{
		scanf("%d",&K);
		while(K--){scanf("%d%d",&x,&y);Add(f[a[x][y]],f[a[x-1][y]]),Add(f[a[x][y]],f[a[x][y-1]]),Add(f[a[x][y]],f[a[x-1][y-1]]);}
		fl=true;t1=t2=0;dfs1(f[S],A,t1);if(vis[f[T]])fl=false;if(fl)dfs1(f[T],B,t2);
		for(i=1;(i<=t1)&&fl;i++)for(j=1;(j<=t2)&&fl;j++)if(st.count(MK(min(A[i],B[j]),max(A[i],B[j])))/*ha.Fin(w1[A[i]]^w1[B[j]],MK(min(A[i],B[j]),max(A[i],B[j])))*/)fl=false;
		printf("%s\n",fl?"YES":"NO");fflush(stdout);for(i=1;i<=num;i++)x=c[i],vi[x]=vis[x]=0,h[x]=0;cnt=0;num=0;vis[f[S]]=vis[f[T]]=0;
	}return 0;
}


#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define PR pair
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define REP(i, x, y)   for(int i = (int)(x); i <= (int)(y); i++)
#define FOR(i, x, y)   for(int i = (int)(x); i <  (int)(y); i++)
#define PER(i ,x, y)  for(int i = (int)(x); i >= (int)(y); i--)
#define CH	         ch = getchar()
#define Exit(...)    printf(__VA_ARGS__), exit(0)
#define dln()        fprintf(stderr,"\n")
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef double	  db;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI > VII;
typedef PR<int,int> PII;
typedef vector<PII> VPI;
const	int inf=2e9;
const	LL Inf=1e10;
const	int P=1e9+7;
const	int N=1005;

inline LL IN(){
	LL x = 0;
	int ch = 0, f = 0;
	for (CH; ch != -1 && (ch < 48 || ch > 57); CH) f = (ch == '-');
	for (; ch >= 48 && ch <= 57; CH) x = (x << 1) + (x << 3) + ch - '0';
	return f ? (-x) : x;
}
template<typename T> inline int chkmin(T &a, const T &b){if(b < a) return a = b, 1; return 0;}
template<typename T> inline int chkmax(T &a, const T &b){if(b > a) return a = b, 1; return 0;}

void renew(int &x, const int &y){
	x += y;
	if(x >= P) x -= P;
	if(x <  0) x += P;
}

int Pow(int x, int y, int p){
	int a = 1;
	for (; y; y >>= 1, x = (LL)x * x %p) if(y & 1) a=(LL)a * x%p;
	return a;
}

int h, w, q, cnt;
int id[N][N], vis[N][N], fa[N * N];
char str[N][N];
int ban[N][N];
struct opt_save{
	int *ptr;
	int val;
	opt_save() {}
	opt_save(int *a, const int &b){
		ptr = a, val = b;
	}
	void backtrace(){
		*ptr = val;
	}
}pool[N * N], *cur = pool;

void dfs(int x, int y){
	if(x < 0 || x > h + 1 || y < 0 || y > w + 1) return;
	if(!ban[x][y] || vis[x][y]) return;
	vis[x][y] = 1;
	id[x][y] = cnt;
	REP(i, x - 1, x + 1)
	REP(j, y - 1, y + 1) dfs(i, j);
}

void back(){
	for(; cur > pool; cur --) cur -> backtrace();
}

void Set(int *x, int y){
	++cur;
	*cur = opt_save(x, *x);
	*x = y;
}

int get(int x){
	if(fa[x] == x) return x;
	return fa[x] = get(fa[x]);
}

void merge(int x, int y){
	x = get(x);
	y = get(y);
	Set(&fa[x], y);
}

int gx[15], gy[15], gtot, S, T;
set<int> st;

void add(int x, int y){
	++cnt;
	Set(&ban[x][y], 1);
	Set(&id[x][y], cnt);
	REP(i, x - 1, x + 1)
	REP(j, y - 1, y + 1){
		if(i < 0 || i > h + 1 || j < 0 || j > w + 1) continue;
		if(!ban[i][j])continue;
		merge(cnt, id[i][j]);
	}
	REP(i, x - 1, x + 1)
	REP(j, y - 1, y + 1){
		if(i < 0 || i > h + 1 || j < 0 || j > w + 1) continue;
		if(!ban[i][j])continue;
		st.insert(id[i][j]);
	}
}

int chk(int x, int y){
	REP(i, x - 2, x + 2)
	REP(j, y - 2, y + 2){
		if(i < 0 || i > h + 1 || j < 0 || j > w + 1) continue;
		if(!ban[i][j])continue;
		int p = id[i][j];
		if(get(p) == get(S) && get(id[x][y]) == get(T)) return 1;
		if(get(p) == get(T) && get(id[x][y]) == get(S)) return 1;
	}
	return 0;
}

set<PII> e;

bool calc(){
	scanf("%d", &gtot);
	REP(i, 1, gtot) scanf("%d%d", gx + i, gy + i);
	REP(i, 1, gtot) add(gx[i], gy[i]);
	for(auto u : st) if(get(u) == get(S))
	for(auto v : st) if(get(v) == get(T)){
		if(e.count(mk(u, v))) return 0;
	}
	REP(i, 1, gtot) if(chk(gx[i], gy[i])) return 0;
	return 1;
}

int main(){
	scanf("%d%d%d", &h, &w, &q);
	REP(i, 1, h) scanf("%s", str[i] + 1);
	REP(i, 1, h) REP(j, 1, w){
		ban[i][j] = str[i][j] == '#';
	}
	REP(i, 3, h + 1) ban[i][0] = 1;
	REP(i, 3, w + 1) ban[0][i] = 1;
	REP(i, 1, w - 2) ban[h + 1][i] = 1;
	REP(i, 1, h - 2) ban[i][w + 1] = 1;
	REP(i, 0, h + 1)
	REP(j, 0, w + 1)if(ban[i][j] && !id[i][j]){
		id[i][j] = ++cnt;
		dfs(i, j);
	}
	REP(i, 0, h + 1)
	REP(j, 0, w + 1)if(ban[i][j])
	REP(x, i - 2, i + 2)
	REP(y, j - 2, j + 2){
		if(x < 0 || x > h + 1 || y < 0 || y > w + 1 || !ban[x][y]) continue;
		e.insert(mk(id[i][j], id[x][y]));
	}
	S = id[0][3];
	T = id[3][0];
	REP(i, 1, h * w) fa[i] = i;
	while(q--){
		gtot = 0;
		st.clear();
		st.insert(S);
		st.insert(T);
		puts(calc() ? "YES" : "NO");
		fflush(stdout);
		back();
	}
	return 0;
}


#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define PR pair
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define REP(i, x, y)   for(int i = (int)(x); i <= (int)(y); i++)
#define FOR(i, x, y)   for(int i = (int)(x); i <  (int)(y); i++)
#define PER(i ,x, y)  for(int i = (int)(x); i >= (int)(y); i--)
#define CH	         ch = getchar()
#define Exit(...)    printf(__VA_ARGS__), exit(0)
#define dln()        fprintf(stderr,"\n")
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef double	  db;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI > VII;
typedef PR<int,int> PII;
typedef vector<PII> VPI;
const	int inf=2e9;
const	LL Inf=1e10;
const	int P=1e9+7;
const	int N=1005;

inline LL IN(){
	LL x = 0;
	int ch = 0, f = 0;
	for (CH; ch != -1 && (ch < 48 || ch > 57); CH) f = (ch == '-');
	for (; ch >= 48 && ch <= 57; CH) x = (x << 1) + (x << 3) + ch - '0';
	return f ? (-x) : x;
}
template<typename T> inline int chkmin(T &a, const T &b){if(b < a) return a = b, 1; return 0;}
template<typename T> inline int chkmax(T &a, const T &b){if(b > a) return a = b, 1; return 0;}

void renew(int &x, const int &y){
	x += y;
	if(x >= P) x -= P;
	if(x <  0) x += P;
}

int Pow(int x, int y, int p){
	int a = 1;
	for (; y; y >>= 1, x = (LL)x * x %p) if(y & 1) a=(LL)a * x%p;
	return a;
}

int h, w, q, cnt;
int id[N][N], vis[N][N], fa[N * N];
char str[N][N];
int ban[N][N];
struct opt_save{
	int *ptr;
	int val;
	opt_save() {}
	opt_save(int *a, const int &b){
		ptr = a, val = b;
	}
	void backtrace(){
		*ptr = val;
	}
}pool[N * N], *cur = pool;

void dfs(int x, int y){
	if(x < 0 || x > h + 1 || y < 0 || y > w + 1) return;
	if(!ban[x][y] || vis[x][y]) return;
	vis[x][y] = 1;
	id[x][y] = cnt;
	REP(i, x - 1, x + 1)
	REP(j, y - 1, y + 1) dfs(i, j);
}

void back(){
	for(; cur > pool; cur --) cur -> backtrace();
}

void Set(int *x, int y){
	++cur;
	*cur = opt_save(x, *x);
	*x = y;
}

int get(int x){
	if(fa[x] == x) return x;
	return fa[x] = get(fa[x]);
}

void merge(int x, int y){
	x = get(x);
	y = get(y);
	Set(&fa[x], y);
}

int gx[15], gy[15], gtot, S, T;
set<int> st;

void add(int x, int y){
	++cnt;
	Set(&ban[x][y], 1);
	Set(&id[x][y], cnt);
	REP(i, x - 1, x + 1)
	REP(j, y - 1, y + 1){
		if(i < 0 || i > h + 1 || j < 0 || j > w + 1) continue;
		if(!ban[i][j])continue;
		merge(cnt, id[i][j]);
	}
	REP(i, x - 1, x + 1)
	REP(j, y - 1, y + 1){
		if(i < 0 || i > h + 1 || j < 0 || j > w + 1) continue;
		if(!ban[i][j])continue;
		st.insert(id[i][j]);
	}
}

int chk(int x, int y){
	REP(i, x - 2, x + 2)
	REP(j, y - 2, y + 2){
		if(i < 0 || i > h + 1 || j < 0 || j > w + 1) continue;
		if(!ban[i][j])continue;
		int p = id[i][j];
		if(get(p) == get(S) && get(id[x][y]) == get(T)) return 1;
		if(get(p) == get(T) && get(id[x][y]) == get(S)) return 1;
	}
	return 0;
}

set<PII> e;

bool calc(){
	scanf("%d", &gtot);
	REP(i, 1, gtot) scanf("%d%d", gx + i, gy + i);
	REP(i, 1, gtot) add(gx[i], gy[i]);
	for(auto u : st) if(get(u) == get(S))
	for(auto v : st) if(get(v) == get(T)){
		if(e.count(mk(u, v))) return 0;
	}
	REP(i, 1, gtot) if(chk(gx[i], gy[i])) return 0;
	return 1;
}

int main(){
	scanf("%d%d%d", &h, &w, &q);
	REP(i, 1, h) scanf("%s", str[i] + 1);
	REP(i, 1, h) REP(j, 1, w){
		ban[i][j] = str[i][j] == '#';
	}
	REP(i, 3, h + 1) ban[i][0] = 1;
	REP(i, 3, w + 1) ban[0][i] = 1;
	REP(i, 1, w - 2) ban[h + 1][i] = 1;
	REP(i, 1, h - 2) ban[i][w + 1] = 1;
	REP(i, 0, h + 1)
	REP(j, 0, w + 1)if(ban[i][j] && !id[i][j]){
		id[i][j] = ++cnt;
		dfs(i, j);
	}
	REP(i, 0, h + 1)
	REP(j, 0, w + 1)if(ban[i][j])
	REP(x, i - 2, i + 2)
	REP(y, j - 2, j + 2){
		if(x < 0 || x > h + 1 || y < 0 || y > w + 1 || !ban[x][y]) continue;
		e.insert(mk(id[i][j], id[x][y]));
	}
	S = id[0][3];
	T = id[3][0];
	REP(i, 1, h * w) fa[i] = i;
	while(q--){
		gtot = 0;
		int gcnt = cnt;
		st.clear();
		st.insert(S);
		st.insert(T);
		puts(calc() ? "YES" : "NO");
		fflush(stdout);
		back();
		cnt = gcnt;
	}
	return 0;
}


#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int,int>pii;
#define SIZE 2000000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	void init()
	{
		for(int i=0;i<SIZE;i++)
		{
			par[i]=i;
			ran[i]=0;
		}
	}
	int find(int a)
	{
		if(a==par[a])return a;
		else return par[a]=find(par[a]);
	}
	void unite(int a,int b)
	{
		a=find(a);
		b=find(b);
		if(a==b)return;
		if(ran[a]>ran[b])
		{
			par[b]=a;
		}
		else
		{
			par[a]=b;
		}
		if(ran[a]==ran[b])ran[b]++;
	}
};
unionfind uf;
int map[1006][1006];
int dat[1006][1006];
void dfs(int x,int y,int c)
{
	if(dat[x][y]!=0)return;
	dat[x][y]=c;
	for(int i=-1;i<=1;i++)for(int j=-1;j<=1;j++)if(map[x+i][y+j])dfs(x+i,y+j,c);
}
int main()
{
	int mx,my,query;
	scanf("%d%d%d",&mx,&my,&query);
	for(int i=5;i<=my+3;i++)map[2][i]=1;
	for(int i=2;i<=my;i++)map[mx+3][i]=1;
	for(int i=5;i<=mx+3;i++)map[i][2]=1;
	for(int i=2;i<=mx;i++)map[i][my+3]=1;
	for(int i=3;i<=mx+2;i++)
	{
		for(int j=3;j<=my+2;j++)
		{
			char z;
			scanf(" %c",&z);
			if(z=='#')map[i][j]=1;
		}
	}
	int pt=1;
	for(int i=0;i<=mx+5;i++)
	{
		for(int j=0;j<=my+5;j++)
		{
			if(map[i][j]!=0&&dat[i][j]==0)dfs(i,j,pt++);
		}
	}
	set<pii>se;
	for(int i=0;i<=mx+5;i++)
	{
		for(int j=0;j<=my+5;j++)
		{
			if(map[i][j]==0)continue;
			for(int x=-2;x<=2;x++)
			{
				for(int y=-2;y<=2;y++)
				{
					if(map[i+x][j+y]!=0&&dat[i][j]!=dat[i+x][j+y])
					{
						se.insert(make_pair(dat[i][j],dat[i+x][j+y]));
					}
				}
			}
		}
	}
	/*for(int i=0;i<=mx+6;i++)
	{
		for(int j=0;j<=my+6;j++)
		{
			printf("%c",'A'+dat[i][j]);
		}
		printf("\n");
	}*/
	int st=dat[2][my+3],go=dat[mx+3][2];
	uf.init();
	for(int p=0;p<query;p++)
	{
		int n;
		scanf("%d",&n);
		vector<pii>vec;
		for(int i=0;i<n;i++)
		{
			int za,zb;
			scanf("%d%d",&za,&zb);
			za+=2,zb+=2;
			dat[za][zb]=pt++;
			map[za][zb]=1;
			vec.push_back(make_pair(za,zb));
		}
		vector<int>lis;
		for(int i=0;i<n;i++)
		{
			int nx=vec[i].first,ny=vec[i].second;
			for(int x=-1;x<=1;x++)
			{
				for(int y=-1;y<=1;y++)
				{
					if(map[nx+x][ny+y])
					{
						uf.unite(dat[nx][ny],dat[nx+x][ny+y]);
						lis.push_back(dat[nx+x][ny+y]);
					}
				}
			}
		}
		lis.push_back(st);
		lis.push_back(go);
		if(uf.find(st)==uf.find(go))
		{
			goto l01;
		}
		for(int i=0;i<n;i++)
		{
			int nx=vec[i].first,ny=vec[i].second;
			if(uf.find(dat[nx][ny])!=uf.find(st)&&uf.find(dat[nx][ny])!=uf.find(go))continue;
			for(int x=-2;x<=2;x++)
			{
				for(int y=-2;y<=2;y++)
				{
					if(map[nx+x][ny+y])
					{
						if((uf.find(dat[nx][ny])==uf.find(st)&&uf.find(dat[nx+x][ny+y])==uf.find(go))||(uf.find(dat[nx][ny])==uf.find(go)&&uf.find(dat[nx+x][ny+y])==uf.find(st)))
						{
							goto l01;
						}
					}
				}
			}
		}
		for(int i=0;i<lis.size();i++)
		{
			for(int j=0;j<lis.size();j++)
			{
				if((uf.find(lis[i])==uf.find(st)&&uf.find(lis[j])==uf.find(go))||uf.find(lis[i])==uf.find(go)&&uf.find(lis[j])==uf.find(st))
				{
					if(se.find(make_pair(lis[i],lis[j]))!=se.end())goto l01;
				}
			}
		}
		printf("YES\n");
		if(false)
		{
l01:;
			printf("NO\n");
		}
		for(int i=0;i<lis.size();i++)
		{
			uf.par[lis[i]]=lis[i];
			uf.ran[lis[i]]=0;
		}
		for(int i=0;i<vec.size();i++)
		{
			int x=vec[i].first,y=vec[i].second;
			uf.par[dat[x][y]]=dat[x][y];
			uf.ran[dat[x][y]]=0;
			dat[x][y]=0;
			map[x][y]=0;
		}
		fflush(stdout);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r)for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define N 1010
const int dx[]={-1,-1,0,1,1,1,0,-1};
const int dy[]={0,1,1,1,0,-1,-1,-1};

int n,m,Q,S,T,cnt,flag;
int ch[N][N],id[N][N];
char s[N];
int fa[N*N];
set<pii>se;

int find(int x){return x==fa[x] ? x : fa[x]=find(fa[x]);}
int find2(int x){return x==fa[x] ? x : find(fa[x]);}
pii get(int x,int y){return mp(min(x,y),max(x,y));}
void merge(int x,int y){fa[find2(x)]=find2(y);}

int K,top,ans;
int bx[N],by[N],st[N];
int main()
{
scanf("%d%d%d",&n,&m,&Q);
for(int i=1;i<=n;i++){
scanf("%s",s+1);
for(int j=1;j<=m;j++)ch[i][j]=(s[j]=='#');
}
S=++cnt;T=++cnt;
rep(i,1,n)rep(j,1,m)id[i][j]=++cnt;
rep(i,1,n){ch[i][0]=ch[i][m+1]=1;id[i][0]=S;id[i][m+1]=T;}
rep(i,1,m){ch[0][i]=ch[n+1][i]=1;id[0][i]=T;id[n+1][i]=S;}
rep(i,1,cnt)fa[i]=i;
rep(i,1,n)rep(j,1,m)if(ch[i][j]){
rep(k,0,7){
int nx=i+dx[k],ny=j+dy[k];
if(ch[nx][ny])fa[find(id[i][j])]=find(id[nx][ny]);
}
}
rep(i,1,n)rep(j,1,m){
if(i==1&&j==1)continue;
if(i==n&&j==m)continue;
rep(k,0,7)rep(l,k+1,7){
int nx=i+dx[k],ny=j+dy[k];
int mx=i+dx[l],my=j+dy[l];
se.insert(get(find(id[nx][ny]),find(id[mx][my])));
if(get(find(id[nx][ny]),find(id[mx][my]))==get(find(S),find(T)))flag=1,i=n+1,j=m+1;
}
}
if(flag){rep(i,1,Q)puts("NO");return 0;}

while(Q--){
scanf("%d",&K);
top=0;
rep(i,1,K){
scanf("%d%d",&bx[i],&by[i]);ch[bx[i]][by[i]]=1;
st[++top]=find(id[bx[i]][by[i]]);
rep(k,0,7){
int nx=bx[i]+dx[k],ny=by[i]+dy[k];
if(ch[nx][ny])st[++top]=find(id[nx][ny]);
}
}
st[++top]=find(S);st[++top]=find(T);
sort(st+1,st+top+1);
top=unique(st+1,st+top+1)-st-1;
rep(i,1,K)rep(k,0,7){
int nx=bx[i]+dx[k],ny=by[i]+dy[k];
if(ch[nx][ny])merge(id[nx][ny],id[bx[i]][by[i]]);
}
ans=1;
rep(i,1,top)if(find2(st[i])==find2(S))
rep(j,1,top)if(find2(st[j])==find2(T)&&se.find(get(st[i],st[j]))!=se.end())
ans=0;
puts(ans ? "YES" : "NO");fflush(stdout);
rep(i,1,K)ch[bx[i]][by[i]]=0;
while(top)fa[st[top]]=st[top],top--;
}
return 0;
}


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

namespace TYC
{
	typedef long long ll;
	typedef pair<int, int> pii;
	const int M = 1002, N = M * M;
	const int dx[] = {0, 0, -1, 1, 1, 1, -1, -1}, dy[] = {1, -1, 0, 0, -1, 1, -1, 1};

	int n, m, q, S, T, top, id[M][M], fa[N], modify[N], li[N], dep[N];
	char G[M][M];
	pii opt[11];
	struct node { int x, y, d; } sta[N];
	struct cmp
	{
		size_t operator () (const pii &a) const { return (ll)a.first * 100010 + a.second; }
	};
	unordered_set<pii, cmp> s;

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	namespace DSU
	{
		int update(const int x) { return fa[x] == x ? x : fa[x] = update(fa[x]); }

		inline int find(int x)
		{
			while (fa[x] != x)
				x = fa[x];
			return x;
		}

		inline void connect(int x, int y)
		{
			if ((x = find(x)) == (y = find(y)))
				return;
			if (dep[x] < dep[y])
				swap(x, y);
			sta[++top] = (node){x, y, dep[x]};
			fa[y] = x;
			dep[x] = max(dep[x], dep[y] + 1);
		}

		inline void restore(const int lim)
		{
			while (top > lim)
			{
				node &p = sta[top--];
				dep[p.x] = p.d;
				fa[p.y] = p.y;
			}
		}
	}
	using namespace DSU;

	void work()
	{
		n = read(), m = read(), q = read();
		for (int i = 1; i <= n; i++)
			scanf("%s", G[i] + 1);
		int tot = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				id[i][j] = ++tot;
		S = ++tot, T = ++tot;
		for (int i = 1; i <= tot; i++)
			fa[i] = i;

		for (int i = 1; i <= n; i++)
		{
			id[i][0] = S, id[i][m + 1] = T;
			G[i][0] = G[i][m + 1] = '#';
		}
		for (int i = 1; i <= m; i++)
		{
			id[0][i] = T, id[n + 1][i] = S;
			G[0][i] = G[n + 1][i] = '#';
		}

		for (int x = 1; x <= n; x++)
			for (int y = 1; y <= m; y++)
				if (G[x][y] == '#')
					for (int k = 0; k < 8; k++)
					{
						int tx = x + dx[k], ty = y + dy[k];
						if (G[tx][ty] == '#')
							fa[update(id[x][y])] = update(id[tx][ty]);
					}
		for (int i = 1; i <= tot; i++)
			update(i);

		int noans = 0;
		for (int x = 1; x <= n; x++)
			for (int y = 1; y <= m; y++)
			{
				if ((x == 1 && y == 1) || (x == n && y == m))
					continue;
				for (int i = 0; i < 8; i++)
					for (int j = i + 1; j < 8; j++)
					{
						int a = fa[id[x + dx[i]][y + dy[i]]];
						int b = fa[id[x + dx[j]][y + dy[j]]];
						if (a > b)
							swap(a, b);
						s.insert(pii(a, b));
						if (a == S && b == T)
							noans = 1, x = n + 1, y = m + 1;
					}
			}
		if (noans)
		{
			while (q--)
				puts("NO");
			return;
		}

		for (int day = 1; day <= q; day++)
		{
			int num = read(), cnt = 0, last = top;
			for (int i = 1, x, y; i <= num; i++)
			{
				x = read(), y = read();
				opt[i] = pii(x, y);
				modify[i] = (G[x][y] != '#');
				G[x][y] = '#';
				li[++cnt] = find(id[x][y]);
				for (int k = 0; k < 8; k++)
				{
					int tx = x + dx[k], ty = y + dy[k];
					if (G[tx][ty] == '#')
						li[++cnt] = find(id[tx][ty]);
				}
			}
			li[++cnt] = find(S);
			li[++cnt] = find(T);
			sort(li + 1, li + 1 + cnt);
			cnt = unique(li + 1, li + 1 + cnt) - li - 1;
			for (int i = 1; i <= num; i++)
			{
				int x = opt[i].first, y = opt[i].second;
				for (int k = 0; k < 8; k++)
				{
					int tx = x + dx[k], ty = y + dy[k];
					if (G[tx][ty] == '#')
						connect(id[x][y], id[tx][ty]);
				}
			}
			bool ans = false;
			for (int i = 1; i <= cnt && !ans; i++)
				if (find(li[i]) == find(S))
					for (int j = 1; j <= cnt && !ans; j++)
					{
						int a = li[i], b = li[j];
						if (a > b)
							swap(a, b);
						if (find(li[j]) == find(T) && s.count(pii(a, b)))
							ans = true;
					}
			puts(ans ? "NO" : "YES");
			fflush(stdout);
			for (int i = 1; i <= num; i++)
				if (modify[i])
					G[opt[i].first][opt[i].second] = '.';
			restore(last);
		}
	}
}

int main()
{
	TYC::work();
	return 0;
}


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

#define pii pair<int, int>

typedef class Dsu {
  public:
    int *uf, *sz;
    boolean durable;
    stack<pii> opt;

    void init(int n) {
      durable = false;
      uf = new int[(n + 1)];
      sz = new int[(n + 1)];
      for (int i = 0; i <= n; i++)
        uf[i] = i, sz[i] = 1;
    }

    int _find(int x) {
      return uf[x] == x ? x : find(uf[x]);
    }
    int _find2(int x) {
      while (x ^ uf[x])
        x = uf[x];
      return x;
    }
    int find(int x) {
      return durable ? _find2(x) : _find(x);
    }
    boolean unit(int x, int y) {
      x = find(x), y = find(y);
      if (sz[x] > sz[y])
        swap(x, y);
      if (x ^ y) {
        if (durable) {
          opt.push(pii(x, uf[x]));
        }
        uf[x] = y;
        sz[y] += sz[x];
        return true;
      }
      return false;
    }

    void revoke() {
      int x = opt.top().first, fx = opt.top().second;
      int y = find(x);
      sz[y] -= sz[x];
      uf[x] = fx;
      opt.pop();
    }
    boolean have_last() {
      return !opt.empty();
    }
    int operator [] (int x) {
      return find(x);
    }
} Dsu;

const int N = 1005;

int n, m, q;
char G[N][N];
vector<pii> mov;
set<int> nearby[N * N];

int S, T;
Dsu uf;

boolean in_range(int x, int y) {
  return x >= 0 && x <= n + 1 && y >= 0 && y <= m + 1;
}
int id(int x, int y) {
  //  assert(in_range(x, y));
  return x * (m + 2) + y;
}
boolean can_block(int x, int y) {
  if (!in_range(x, y))
    return false;
  if (x < 1 || x > n || y < 1 || y > m)
    return false;
  if (x == 1 && y == 1)
    return false;
  if (x == n && y == m)
    return false;
  return true;
}

int add_around(int x, int y) {
  int p = id(x, y), rt = 0;
  for (auto d : mov) {
    int nx = d.first + x, ny = d.second + y;
    if (in_range(nx, ny) && G[nx][ny] == '#')
      rt += uf.unit(p, id(nx, ny));
  }
  return rt;
}

int main() {
  //  freopen("a.in", "r", stdin);
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      if (dx || dy) {
        mov.emplace_back(dx, dy);
      }
    }
  }
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", G[i] + 1);
  }
  G[0][0] = G[1][0] = G[0][1] = '.';
  G[n + 1][m + 1] = G[n][m + 1] = G[n + 1][m] = '.';
  for (int i = 2; i <= m + 1; i++) {
    G[0][i] = '#';
    G[n + 1][i - 2] = '#';
  }
  for (int i = 2; i <= n + 1; i++) {
    G[i][0] = '#';
    G[i - 2][m + 1] = '#';
  }
  uf.init((n + 2) * (m + 2));
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      if (G[i][j] != '#')
        continue;
      add_around(i, j);
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      if (G[i][j] == '#') {
        for (auto d : mov) {
          int x = i + d.first, y = j + d.second;
          if (!can_block(x, y) || G[x][y] != '.')
            continue;
          for (auto d2 : mov) {
            int nx = x + d2.first, ny = y + d2.second;
            if (in_range(nx, ny) && uf[id(nx, ny)] ^ uf[id(i, j)]) {
              nearby[uf[id(i, j)]].insert(uf[id(nx, ny)]);
            }
          }
        }
      }
    }
  }
  S = uf[id(0, 2)], T = uf[id(2, 0)];
  uf.durable = true;
  while (q--) {
    int num;
    vector<pii> P;
    scanf("%d", &num);
    for (int i = 0, x, y; i < num; i++) {
      scanf("%d%d", &x, &y);
      G[x][y] = '#';
      P.emplace_back(x, y);
    }
    vector<int> block;
    vector<int> bs {uf[S]}, bt {uf[T]};
    for (auto p : P) {
      int x = p.first, y = p.second;
      for (auto d : mov) {
        int nx = d.first + x, ny = d.second + y;
        if (in_range(nx, ny) && G[nx][ny] == '#') {
          block.push_back(uf[id(nx, ny)]);
          uf.unit(id(x, y), id(nx, ny));
        }
      }
    }
    if (uf[S] == uf[T]) {
      puts("NO");
      goto query_end;
    }
    for (auto p : P) {
      int px = p.first, py = p.second;
      for (auto d : mov) {
        int x = px + d.first, y = py + d.second;
        if (!can_block(x, y) || G[x][y] != '.')
          continue;
        boolean ns = false, nt = false;
        for (auto d2 : mov) {
          int nx = x + d2.first, ny = y + d2.second;
          if (!ns && uf[id(nx, ny)] == uf[S])
            ns = true;
          if (!nt && uf[id(nx, ny)] == uf[T])
            nt = true;
        }
        if (ns && nt) {
          puts("NO");
          goto query_end;
        }
      }
    }
    sort(block.begin(), block.end());
    block.erase(unique(block.begin(), block.end()), block.end());
    for (auto bid : block) {
      int fx = uf[bid];
      if (fx == uf[S]) {
        bs.push_back(bid);
      } else if (fx == uf[T]) {
        bt.push_back(bid);
      }
    }
    for (auto x : bs) {
      for (auto y : bt) {
        if (nearby[x].count(y)) {
          puts("NO");
          goto query_end;
        }
      }
    }
    puts("YES");
query_end:
    for (auto p : P)
      G[p.first][p.second] = '.';
    while (uf.have_last())
      uf.revoke();
    fflush(stdout);
  }
  return 0;
}
//hellobig_tq


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

unordered_map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T;
int p1[maxm], p2[maxm], n, m, q;

int stk[maxn], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {u = find2(u); v = find2(v); u != v ? (stk[++top] = u, stk[++top] = v, p2[u] = v) : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		if (!OK)
		rep(i, tot) if (find2(i) == find2(S))
		rep(j, tot) if (find2(j) == find2(T))
			OK |= query(i, j);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T, hav[maxm];
int p1[maxm], p2[maxm], n, m, q;

int stk[maxn], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {u = find2(u); v = find2(v); if (u > v) swap(u, v); u != v ? (stk[++top] = u, stk[++top] = v,p2[u] = v) : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {hav[x] = hav[y] = true; container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		for (int i = 1; i <= top && !OK; i++) if (find2(stk[i]) == find2(S) && hav[stk[i]])
		for (int j = 1; j <= top && !OK; j++) if (find2(stk[j]) == find2(T) && hav[stk[j]])
			OK |= query(stk[i], stk[j]);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T, hav[maxm];
int p1[maxm], p2[maxm], n, m, q;

int stk[maxn], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {u = find2(u); v = find2(v); if (u > v) swap(u, v); u != v ? (stk[++top] = u, p2[u] = v) : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {hav[x] = hav[y] = true; container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		for (int i = 1; i <= tot && !OK; i++) if (find2(stk[i]) == find2(S) && hav[stk[i]])
		for (int j = 1; j <= tot && !OK; j++) if (find2(stk[j]) == find2(T) && hav[stk[j]])
			OK |= query(stk[i], stk[j]);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 8e5 + 5;
const int inf = 1 << 28;

vector<int> adj[maxn];
#define add(u, v) adj[u].pb(v)

int siz[maxn], top[maxn], par[maxn], mson[maxn];
int ans[maxn], n, m, ord[maxn], x[maxn], t[maxn];
int dfn[maxn], edfn[maxn], idx, pos[maxn], dep[maxn];
int maxd[maxn], rst[maxn], eff[maxn];

#define ls rt << 1
#define rs rt << 1 | 1
void build(int rt, int L, int R)
{
	rst[rt] = eff[rt] = -inf;
	if (L >= R) {maxd[rt] = dep[pos[L]]; return ;}
	int mid = L + R >> 1;
	build(ls, L, mid);
	build(rs, mid + 1, R);
	maxd[rt] = max(maxd[ls], maxd[rs]);
}
void effect(int rt, int val)
{
	eff[rt] = max(eff[rt], val);
	rst[rt] = max(rst[rt], maxd[rt] * 2 + val);
}
void pushdown(int rt)
{
	effect(ls, eff[rt]);
	effect(rs, eff[rt]);
}
void modify(int rt, int L, int R, int l, int r, int val)
{
	if (L >= l && R <= r) {effect(rt, val); return ;}
	int mid = L + R >> 1; pushdown(rt);
	if (l <= mid) modify(ls, L, mid, l, r, val);
	if (r > mid) modify(rs, mid + 1, R, l, r, val);
	rst[rt] = max( rst[ls], rst[rs]);
}
int query(int rt, int L, int R, int l, int r, int val)
{
	if (rst[rt] <= val) return 0;
	if (L >= R) return pos[L];
	int mid = L + R >> 1; pushdown(rt);
	if (r > mid) {
		int res = query(rs, mid + 1, R, l, r, val);
		if (res) return res;
	}
	if (l <= mid) {
		int res = query(ls, L, mid, l, r, val);
		if (res) return res;
	}
	return 0;
}

void dfs1(int u)
{
	siz[u] = 1;
	for (auto v : adj[u]) if (v != par[u])
	{
		par[v] = u; dep[v] = dep[u] + 1; dfs1(v);
		siz[u] += siz[v]; siz[v] > siz[mson[u]] ? mson[u] = v : 0;
	}
}
void dfs2(int u, int tp)
{
	dfn[u] = edfn[n] = ++idx; pos[idx] = u; top[u] = tp;
	if (mson[u]) dfs2(mson[u], tp);
	for (auto v : adj[u])
		if (v != par[u] && v != mson[u]) dfs2(v, v);
	edfn[u] = idx;
}
void modify(int u, int t, int val)
{
	while (top[u] != top[t])
	{
		modify(1, 1, n, dfn[top[u]], dfn[u], val);
		u = par[top[u]];
	}
	modify(1, 1, n, dfn[t], dfn[u], val);
}
int solve(int u, int val)
{
	while (top[u] != 1)
	{
		int res = query(1, 1, n, dfn[top[u]], dfn[u], val);
		if (res) return res;
		u = par[top[u]];
	}
	int res = query(1, 1, n, 1, dfn[u], val);
	return res ? res : 1;
}
bool cmp(int a, int b) {
	int ta = dep[x[a]] + t[a];
	int tb = dep[x[b]] + t[b];
	return ta != tb ? ta < tb : x[a] < x[b];
}
int main()
{
	#ifdef FILE_TEST
		freopen("tree.in", "r", stdin);
	#endif

	scanf("%d %d", &n, &m); ++n;
	for (int v, i = 2; i <= n; i++)
		scanf("%d", &v), add(v + 1, i);
	dfs1(1); dfs2(1, 1); build(1, 1, n);

	repi(m) scanf("%d %d", &x[i], &t[i]);
	repi(m) ord[i] = i, x[i]++;
	sort(ord + 1, ord + m + 1, cmp);

	repi(m) {
		int o = ord[i] , top = solve(x[o], t[o] + dep[x[o]]);
		ans[o] = t[o] + 2 * (dep[x[o]] - dep[top]);
		modify(x[o], top, ans[o] - dep[x[o]]);
	}
	repi(m) printf("%d ",ans[i]);
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T, hav[maxm];
int p1[maxm], p2[maxm], n, m, q;

int stk[maxm], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {stk[++top] = u, stk[++top] = v; u = find2(u); v = find2(v); u != v ? p2[u] = v : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {hav[x] = hav[y] = true; container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		for (int i = 1; i <= top && !OK; i++) if (find2(stk[i]) == find2(S) && hav[stk[i]])
		for (int j = 1; j <= top && !OK; j++) if (find2(stk[j]) == find2(T) && hav[stk[j]])
			OK |= query(stk[i], stk[j]);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T;
int p1[maxm], p2[maxm], n, m, q;

int stk[maxn], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {u = find2(u); v = find2(v); if (u > v) swap(u, v); u != v ? (stk[++top] = u, p2[u] = v) : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		if (!OK)
		for (int i = 1; i <= tot ; i++) if (find2(i) == find2(S))
		for (int j = 1; j <= tot ; j++) if (find2(j) == find2(T))
			OK |= query(i, j);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

unordered_map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T;
int p1[maxm], p2[maxm], n, m, q;

int stk[maxn], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {u = find2(u); v = find2(v); u != v ? (stk[++top] = u, stk[++top] = v, p2[u] = v) : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		rep(i, tot) if (find2(i) == find2(S))
		rep(j, tot) if (find2(j) == find2(T))
			OK |= query(i, j);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 1 ; i <= (n) ; i++)
#define per(i, n) for (int i = (n) ; i >= 1 ; i--)
#define repi(n) for (int i = 1; i <= (n) ; i++)
#define mabs(n) ((n) > 0 ? (n) : (-n))
#define sqr(n) ((n) * (n))
#define print(V) for (auto v: V) printf("%d ",v)
using namespace std;
typedef pair<int, int> mp;
typedef long long LL ;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 500;

map< LL, bool> container;
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
char str[maxn][maxn];
int id[maxn][maxn], tot, S, T, hav[maxm];
int p1[maxm], p2[maxm], n, m, q;

int stk[maxm], top, x_[maxn], y_[maxn];
int find1(int u) {return p1[u] ? p1[u] = find1(p1[u]) : u;}
int find2(int u) {return p2[u] ? p2[u] = find2(p2[u]) : u;}
void merge1(int u, int v) {u = find1(u); v = find1(v); u != v ? p1[u] = v : 0;}
void merge2(int u, int v) {u = find2(u); v = find2(v); u != v ? (stk[++top] = u, stk[++top] = v, p2[u] = v) : 0;}
bool inG(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m;}
void insert(int x, int y) {hav[x] = hav[y] = true; container[(LL)x * 1000000ll + y] = true;}
bool query(int x, int y) {return container[(LL)x * 1000000ll + y];}

bool check(int x, int y)
{
	if (!inG(x, y)) return false;
	if (x == 1 && y == 1) return false;
	if (x == n && y == m) return false;

	bool conS = false, conT = false;
	rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (find2(id[nx][ny]) == find2(S)) conS = true;
		if (find2(id[nx][ny]) == find2(T)) conT = true;
	}
	return conS && conT;
}
int main()
{
	#ifdef FILE_TEST
		freopen("grid.in", "r", stdin);
	#endif

	scanf("%d %d %d", &n, &m, &q);
	repi(n) scanf("%s", str[i] + 1);
	S = ++tot ; T = ++tot;
	repi(n) rep(j, m) id[i][j] = ++tot;

	repi(m) str[0][i] = '#', id[0][i] = T;
	repi(n) str[i][0] = '#', id[i][0] = S;
	repi(m) str[n + 1][i] = '#', id[n + 1][i] = S;
	repi(n) str[i][m + 1] = '#', id[i][m + 1] = T;
	id[0][0] = ++tot; id[n + 1][m + 1] = ++tot;

	rep(x, n) rep(y, m) if (str[x][y] == '#') rep(k, 8)
	{
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (str[nx][ny] == '#')
			merge1(id[x][y], id[nx][ny]);
	}
	S = find1(S); T = find1(T);
	for (int x = 0 ; x <= n + 1; x++ )
	for (int y = 0 ; y <= m + 1; y++ )
		id[x][y] = find1(id[x][y]);

	rep(x, n) rep(y, m) rep(k1, 8)
	{
		if (x == 1 && y == 1) continue;
		if (x == n && y == m) continue;
		int nx1 = x + dx[k1];
		int ny1 = y + dy[k1];
		if (str[nx1][ny1] != '#') continue;
		rep(k2, 8)
		{
			int nx2 = x + dx[k2];
			int ny2 = y + dy[k2];
			if (str[nx2][ny2] != '#') continue;
			int u = id[nx1][ny1];
			int v = id[nx2][ny2];
			if (u != v) insert(u, v);
		}
	}

	repi(q)
	{
		int r, x, y; bool OK = false;
		scanf("%d", &r);
		repi(r) scanf("%d %d", &x_[i], &y_[i]);
		repi(r) str[x_[i]][y_[i]] = '#';
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			if (str[nx][ny] == '#')
				merge2(id[x_[i]][y_[i]], id[nx][ny]);
		}
		repi(r) rep(k, 8)
		{
			int nx = x_[i] + dx[k];
			int ny = y_[i] + dy[k];
			OK |= check(nx, ny);
		}

		OK |= find2(T) == find2(S);
		for (int i = 1; i <= top && !OK; i++) if (find2(stk[i]) == find2(S) && hav[stk[i]])
		for (int j = 1; j <= top && !OK; j++) if (find2(stk[j]) == find2(T) && hav[stk[j]])
			OK |= query(stk[i], stk[j]);
		repi(r) str[x_[i]][y_[i]] = '.';
		while (top) p2[ stk[top--]] = 0;
		printf("%s\n", OK ? "NO" : "YES");
		fflush(stdout);
	}
	return 0;
}