description: 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  
      
solution: 					/*
  					ID: abdelra29
  LANG: JAVA
  PROG: zerosum
  					*/
  						/*
  						TO LEARN
  				
  						2-euler tour
  					
  						*/
  						/*
  						TO SOLVE 
  						codeforces 722 kavi on pairing duty
  						*/
  						/*
  						bit manipulation shit
  						1-Computer Systems: A Programmer's Perspective
  						2-hacker's delight
  						*/
  						/*
  						TO WATCH
  						
  						*/
  						            import java.util.*;
  								    import java.math.*;
  								    import java.io.*; 
  								    import java.util.stream.Collectors;
  
  								       public class A{
  						            static FastScanner scan=new FastScanner();
  									     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  
  
  		static long gcd(long a,long b)
  		{
  			if(a==0)
  				return b;
  			return gcd(b%a,a);
  		}
  		static long lcm(long a,long b)
  		{
  			return (a*b)/(gcd(a,b));
  		}
  		static int a[][];
  		static int t[][];
  		static int n,m;
  		static void build_y(int vx, int lx, int rx, int vy, int ly, int ry) {
      if (ly == ry) {
          if (lx == rx){
          	//System.out.println("F "+a[lx][ly]);
              t[vx][vy] = a[lx][ly];
          }
          else
              t[vx][vy] = Math.max(t[vx*2][vy] ,t[vx*2+1][vy]);
      } else {
          int my = (ly + ry) / 2;
          build_y(vx, lx, rx, vy*2, ly, my);
          build_y(vx, lx, rx, vy*2+1, my+1, ry);
          t[vx][vy] = Math.max(t[vx][vy*2] , t[vx][vy*2+1]);
      }
  }
  
  static void build_x(int vx, int lx, int rx) {
      if (lx != rx) {
          int mx = (lx + rx) / 2;
          build_x(vx*2, lx, mx);
          build_x(vx*2+1, mx+1, rx);
      }
      build_y(vx, lx, rx, 1, 0, m-1);
  }
  static int sum_y(int vx, int vy, int tly, int try_, int ly, int ry) {
      if (ly > ry) 
          return 0;
      if (ly == tly && try_ == ry)
          return t[vx][vy];
      int tmy = (tly + try_) / 2;
      return Math.max(sum_y(vx, vy*2, tly, tmy, ly, Math.min(ry, tmy)), sum_y(vx, vy*2+1, tmy+1, try_, Math.max(ly, tmy+1), ry));
  }
  
  static int sum_x(int vx, int tlx, int trx, int lx, int rx, int ly, int ry) {
      if (lx > rx)
          return 0;
      if (lx == tlx && trx == rx)
          return sum_y(vx, 1, 0, m-1, ly, ry);
      int tmx = (tlx + trx) / 2;
      return Math.max(sum_x(vx*2, tlx, tmx, lx, Math.min(rx, tmx), ly, ry), sum_x(vx*2+1, tmx+1, trx, Math.max(lx, tmx+1), rx, ly, ry));
  }
  				public static void main(String[] args)  throws Exception 
  						      {
  						 /*
  						 very important tips 
  						 1-just fucking think backwards once in your shitty life
  						 2-consider brute forcing and finding some patterns and observations
  						 3-when you're in contest don't get out because you think there is no enough time
  						
  						 */
  						
  							//scan=new FastScanner("binary.in");
  								///out = new PrintWriter("zerosum.out");
  								 
  								 							 /*
  								 READING 
  							
  								 3-Introduction to DP with Bitmasking codefoces
  								 4-Bit Manipulation hackerearth
  								 5-read more about mobious and inculsion-exclusion 
  								 */
  								 /*
  								this problem boils down to is there a cell (doesn't matter if empty or not) if i start in it i can't get out of the grid 
  								 */
  								
  					
  								    int tt=1;
  								 
  
  				//tt=scan.nextInt();
  		
  //System.out.println(1^2);
  
  				int T=1;
  
  							 outer:while(tt-->0)
  								    {
  								    	 n=scan.nextInt();
  								    	 m=scan.nextInt();
  								    	 t=new int[n*4][m*4];
  								    	char board[][]=new char[n][m];
  								    	for(int i=0;i<n;i++)
  								    		board[i]=scan.next().toCharArray();
  								    	 a=new int[n][m];
  								    	for(int i=1;i<n;i++)
  								    		{
  								    			for(int j=1;j<m;j++)
  								    			{
  								    			//	out.println(board[i-1][j]+" "+board[i][j-1]);
  								    				if(board[i-1][j]=='X'&&board[i][j-1]=='X')
  								    				{
  								    					a[i][j]=1;
  								    					
  								    				}
  								    			}
  								    		}
  								    		build_x(1,0,n-1);
  								    		//out.println(a[1][4]);
  								    		//out.println(sum_x(1,0,n-1,1,4,1,4));
  								    	int q=scan.nextInt();
  								    	
  								    	con:for(int qq=0;qq<q;qq++)
  								    	{
  								    		int x=scan.nextInt()-1,y=scan.nextInt()-1;
  								    		//out.println(sum_x(0,0,n-1,1,n-1,x+1,y));
  								    		if(sum_x(1,0,n-1,1,n-1,x+1,y)>=1)
  								    			out.println("NO");
  								    		else
  								    		out.println("YES");
  								    	}
  								    	
  								    	 
  
  
  
  								    
  
  
  	 }
  
  								
  
  		out.close();
  					}
  					
  			static class Point { int x; int y; 
  				public Point(int x, int y) { this.x = x; this.y = y; } } 
  				static class Triangle { 
  
  					 public static float area(Point A, Point B, Point C) {
  					  float area = (A.x * (B.y - C.y) + B.x * (C.y - A.y) + C.x * (A.y - B.y)) / 2.0f; return Math.abs(area); }
  
  }
  
  
  					static class special{
  					boolean is;
  					char c;
  					public special(boolean is,char c)
  					{
  						this.is=is;
  						this.c=c;
  					}
  
  						 @Override
  								            public int hashCode() {
  								                return (int)(c+ 31 *(is?1:0));
  								            }
  						  @Override
  								            public boolean equals(Object o){
  								            //	System.out.println("FUCK");
  								                if (o == this) return true;
  								                if (o.getClass() != getClass()) return false;
  								                special t = (special)o;
  								                return t.is == is && t.c == c;
  								            }
  					}
  		
  								   
  								     static long binexp(long a,long n)
  								    {
  								        if(n==0)
  								            return 1;
  								        long res=binexp(a,n/2);
  								        if(n%2==1)
  								            return res*res*a;
  								        else 
  								            return res*res;
  								    }
  								     
  								    static long powMod(long base, long exp, long mod) {
  								           if (base == 0 || base == 1) return base;
  								           if (exp == 0) return 1;
  								           if (exp == 1) return (base % mod+mod)%mod;
  								           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
  								           R *= R;
  								           R %= mod;
  								           if ((exp & 1) == 1) {
  								               return (base * R % mod+mod)%mod;
  								           }
  								           else return (R %mod+mod)%mod;
  								       }
  								    static double dis(double x1,double y1,double x2,double y2)
  								    {
  								        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  								    }
  								    static long mod(long x,long y)
  								        {
  								            if(x<0)
  								                x=x+(-x/y+1)*y;
  								            return x%y;
  								        }
  								     public static  long pow(long b, long e) {
  								                long r = 1;
  								                while (e > 0) {
  								                    if (e % 2 == 1) r = r * b ;
  								                    b = b * b;
  								                    e >>= 1;
  								                }
  								                return r;
  								            }
  								    private static void sort(long[] arr) {
  								            List<Long> list = new ArrayList<>();
  								            for (long object : arr) list.add(object);
  								            Collections.sort(list);
  								        //Collections.reverse(list);
  								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  								        }
  								    private static void sort2(long[] arr) {
  								            List<Long> list = new ArrayList<>();
  								            for (Long object : arr) list.add(object);
  								            Collections.sort(list);
  								        Collections.reverse(list);
  								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  								        }
  								     static class FastScanner
  						{
  						    private int BS = 1 << 16;
  						    private char NC = (char) 0;
  						    private byte[] buf = new byte[BS];
  						    private int bId = 0, size = 0;
  						    private char c = NC;
  						    private double cnt = 1;
  						    private BufferedInputStream in;
  						 
  						    public FastScanner() {
  						        in = new BufferedInputStream(System.in, BS);
  						    }
  						 
  						    public FastScanner(String s) {
  						        try {
  						            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  						        } catch (Exception e) {
  						            in = new BufferedInputStream(System.in, BS);
  						        }
  						    }
  						 
  						    private char getChar() {
  						        while (bId == size) {
  						            try {
  						                size = in.read(buf);
  						            } catch (Exception e) {
  						                return NC;
  						            }
  						            if (size == -1) return NC;
  						            bId = 0;
  						        }
  						        return (char) buf[bId++];
  						    }
  						 
  						    public int nextInt() {
  						        return (int) nextLong();
  						    }
  						 
  						    public int[] nextInts(int N) {
  						        int[] res = new int[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = (int) nextLong();
  						        }
  						        return res;
  						    }
  						 
  						    public long[] nextLongs(int N) {
  						        long[] res = new long[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = nextLong();
  						        }
  						        return res;
  						    }
  						 
  						    public long nextLong() {
  						        cnt = 1;
  						        boolean neg = false;
  						        if (c == NC) c = getChar();
  						        for (; (c < '0' || c > '9'); c = getChar()) {
  						            if (c == '-') neg = true;
  						        }
  						        long res = 0;
  						        for (; c >= '0' && c <= '9'; c = getChar()) {
  						            res = (res << 3) + (res << 1) + c - '0';
  						            cnt *= 10;
  						        }
  						        return neg ? -res : res;
  						    }
  						 
  						    public double nextDouble() {
  						        double cur = nextLong();
  						        return c != '.' ? cur : cur + nextLong() / cnt;
  						    }
  						 
  						    public double[] nextDoubles(int N) {
  						        double[] res = new double[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = nextDouble();
  						        }
  						        return res;
  						    }
  						 
  						    public String next() {
  						        StringBuilder res = new StringBuilder();
  						        while (c <= 32) c = getChar();
  						        while (c > 32) {
  						            res.append(c);
  						            c = getChar();
  						        }
  						        return res.toString();
  						    }
  						 
  						    public String nextLine() {
  						        StringBuilder res = new StringBuilder();
  						        while (c <= 32) c = getChar();
  						        while (c != '\n') {
  						            res.append(c);
  						            c = getChar();
  						        }
  						        return res.toString();
  						    }
  						 
  						    public boolean hasNext() {
  						        if (c > 32) return true;
  						        while (true) {
  						            c = getChar();
  						            if (c == NC) return false;
  						            else if (c > 32) return true;
  						        }
  						    }
  						}
  
  								     static class Pair implements Comparable<Pair>{
  								            public long x, y,z;
  								            public Pair(long x1, long y1,long z1) {
  								                x=x1;
  								                y=y1;
  								                z=z1;
  								            }
  								             public Pair(long x1, long y1) {
  								                x=x1;
  								                y=y1;
  								    
  								            }
  								            
  								            @Override
  								            public int hashCode() {
  								                return (int)(x + 31 * y);
  								            }
  								            public String toString() {
  								                return x + " " + y+" "+z;
  								            }
  								            @Override
  								            public boolean equals(Object o){
  								                if (o == this) return true;
  								                if (o.getClass() != getClass()) return false;
  								                Pair t = (Pair)o;
  								                return t.x == x && t.y == y&&t.z==z;
  								            }
  								    public int compareTo(Pair o)
  								    {
  								  	
  								return (int)(x-o.x);
  								     
  								        }
  								     
  								    }
  								}
  								
  								    
  								   
  
  								     
  