The problem statement looms below, filling you with determination.

Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in cells are not exitable. Note that you can exit the grid from any leftmost empty cell (cell in the first column) by going left, and from any topmost empty cell (cell in the first row) by going up.

Let's call a grid determinable if, given only which cells are exitable, we can exactly determine which cells are filled in and which aren't.

You are given a grid a of dimensions n × m , i. e. a grid with n rows and m columns. You need to answer q queries (1 ≤ q ≤ 2 ⋅ 10^5). Each query gives two integers x_1, x_2 (1 ≤ x_1 ≤ x_2 ≤ m) and asks whether the subgrid of a consisting of the columns x_1, x_1 + 1, …, x_2 - 1, x_2 is determinable.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 10^6, nm ≤ 10^6) — the dimensions of the grid a.

n lines follow. The y-th line contains m characters, the x-th of which is 'X' if the cell on the intersection of the the y-th row and x-th column is filled and "." if it is empty.

The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

q lines follow. Each line contains two integers x_1 and x_2 (1 ≤ x_1 ≤ x_2 ≤ m), representing a query asking whether the subgrid of a containing the columns x_1, x_1 + 1, …, x_2 - 1, x_2 is determinable.

Output

For each query, output one line containing "YES" if the subgrid specified by the query is determinable and "NO" otherwise. The output is case insensitive (so "yEs" and "No" will also be accepted).

Example

Input


4 5
..XXX
...X.
...X.
...X.
5
1 3
3 3
4 5
5 5
1 5


Output


YES
YES
NO
YES
NO

Note

For each query of the example, the corresponding subgrid is displayed twice below: first in its input format, then with each cell marked as "E" if it is exitable and "N" otherwise.

For the first query: 
    
    
      
    ..X EEN  
    ... EEE  
    ... EEE  
    ... EEE  
    
    
    
      
      
    

For the second query: 
    
    
      
    X N  
    . E  
    . E  
    . E  
    

Note that you can exit the grid by going left from any leftmost cell (or up from any topmost cell); you do not need to reach the top left corner cell to exit the grid.
    
    
      
      
    

For the third query: 
    
    
      
    XX NN  
    X. NN  
    X. NN  
    X. NN  
    

This subgrid cannot be determined only from whether each cell is exitable, because the below grid produces the above "exitability grid" as well: 
    
    
      
    XX  
    XX  
    XX  
    XX  
    
    
    
      
      
    

For the fourth query: 
    
    
      
    X N  
    . E  
    . E  
    . E  
    
    
    
      
      
    

For the fifth query: 
    
    
      
    ..XXX EENNN  
    ...X. EEENN  
    ...X. EEENN  
    ...X. EEENN  
    

This query is simply the entire grid. It cannot be determined only from whether each cell is exitable because the below grid produces the above "exitability grid" as well: 
    
    
      
    ..XXX  
    ...XX  
    ...XX  
    ...XX  
    
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Map.Entry;


import java.util.Random;
import java.util.TreeSet;

public final class CF_749_D2_C
{


	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void logWln(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputFlush(Object o){try {out.write(""+ o+"\n");out.flush();} catch (Exception e) {}}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}


	static void logBin(int[] tm) {for (int x:tm) logWln(bin(8,x)+" ");log("");}

	static String bin(int L,int x) {
		String s=Integer.toBinaryString(x);
		while (s.length()<L) s="0"+s;
		return s;
	}

	// Global vars
	static BufferedWriter out;
	static InputReader reader;


	static void test() {
		log("testing");

		Random r=new Random();
		int NTESTS=1000000;
		int NMAX=22;
		int VMAX=10;
		for (int t=0;t<NTESTS;t++) {

		}
		log("testing done");

	}

	static class BIT {

		long[] tree;
		int N;

		BIT(int N){
			tree=new long[N+1];
			this.N=N;
		}

		void add(int idx,int val){
			idx++;
			while (idx<=N){
				tree[idx]+=val;
				idx+=idx & (-idx);
			}
		}
		long read(int idx){
			idx++;
			long sum=0;
			while (idx>0){
				sum+=tree[idx];
				idx-=idx & (-idx);
			}
			return sum;
		}

	}


	
	static int[][] dm= {{-1,0},{0,-1}};
	
	static ArrayList<Integer>[] friends;

	static void process() throws Exception {

		log("hello");

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);

		int n=reader.readInt();
		int m=reader.readInt();
		int[][] map=new int[n][m];
		for (int i=0;i<n;i++) {
			String s=reader.readString(m);
			for (int j=0;j<m;j++) {
				if (s.charAt(j)=='X')
					map[i][j]=1;
				else
					map[i][j]=0;
			}
		}
		
		int[][] stack=new int[n*m][2];
		int[][] prev=new int[n*m][2];
		int color=2;
		for (int i=0;i<n;i++)
			for (int j=0;j<m;j++) {
				if (map[i][j]==0) {
					int cur=color++;
					int st=0;
					int h=0;
					stack[st][0]=i;
					stack[st][1]=j;
					prev[h][0]=i;
					prev[h][1]=j;
					map[i][j]=cur;
					st++;
					h++;
					while (st>0) {
						int[] tm=stack[--st];
						int u=tm[0];
						int v=tm[1];
						if (u==0 || v==0) {
							// win
							// we stop there
							while (h>0) {
								int x=prev[h-1][0];
								int y=prev[h-1][1];
								map[x][y]=-1;
								h--;
							}
						} else 
						
						for (int[] delta:dm) {
							int uu=u+delta[0];
							int vv=v+delta[1];
							if (uu>=0 && uu<n && vv>=0 && vv<m) {
								if (map[uu][vv]==0) {
									map[uu][vv]=cur;
									stack[st][0]=uu;
									stack[st][1]=vv;
									st++;
									prev[h][0]=uu;
									prev[h][1]=vv;
									h++;
								} else 
									if (map[uu][vv]==-1) {
										// win
										while (h>0) {
											int x=prev[h-1][0];
											int y=prev[h-1][1];
											map[x][y]=-1;
											h--;
										}
									}
									else {
										// nothing
									}
							} 
						}
					}
					
				}
			}
		
		int[] min=new int[n*m];
		int MX=Integer.MAX_VALUE;
		Arrays.fill(min, MX);
		TreeSet<Integer> lst=new TreeSet<Integer>();

		
		
		
		for (int i=0;i<n;i++)
			for (int j=0;j<m;j++) {
				if (map[i][j]>1) {
					int c=map[i][j];
					min[c]=Math.min(min[c],j);
					lst.add(c);
				}
			}
		
		BIT bt=new BIT(m+1);
		
		for (int c:lst) {
				bt.add(min[c],1);
		}
		
		
		int Q=reader.readInt();

		boolean[] bad=new boolean[Q];
		for (int q=0;q<Q;q++) {
			int x1=reader.readInt()-1;
			int x2=reader.readInt()-1;
			if (x1==x2) {
				output("YES");
			} else {
				long cnt=bt.read(x2)-bt.read(x1);
				if (cnt>0)
					output("NO");
				else
					output("YES");
				
			}
			
			
		}
		

		
		// we find the exitable ones
		// the others are either blocked on enclosed
		// if a subgrid contans enclosed that are really enclosed, we are doomed
		
		
		
		
		try {
			out.close();
		} catch (Exception Ex) {
		}

	}





	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final String readString(int L) throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder(L);
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}
/*

1
10
1 0 0 0 0 1 0 0 1 1

1
12
1 0 0 1 0 0 1 0 0 0 0 1

1
12
1 0 0 1 0 0 1 0 0 0 0 1

3
12
1 0 0 1 0 0 1 0 0 0 0 1
10
1 0 0 0 0 1 0 0 1 1
12
1 0 0 1 0 0 1 0 0 0 0 1

1
11
1 0 0 0 0 0 0 0 1 1 1



19
1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 0 1 1 


19
1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 0 1 0 


19
1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 0 


1
20
1 1 0 0 0 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 

 */