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.util.*;
import java.lang.*;
import java.io.*;
import java.text.DecimalFormat;

public final class Solution {

    static int inf = Integer.MAX_VALUE;
    static long mod = 1000000000 + 7;
   
    

 static void ne(Scanner sc, BufferedWriter op) throws Exception {
     int n=sc.nextInt();
     int m=sc.nextInt();
    int[][] a= new int[n][m];
    for(int i=0;i<n;i++){
        String s=sc.next();
        for(int j=0;j<m;j++){
            if(s.charAt(j)=='X'){
                a[i][j]=1;
            }
        }
    }
    // debug.print2d(a);
    int cc=0;
     int[] arr= new int[m];
     for(int j=0;j<m-1;j++){
        for(int i=1;i<n;i++){
          
            if(a[i][j]==1 && a[i-1][j+1]==1){
                // System.out.print("asdsa");
                cc++;
            
            }

          
        }
        arr[j+1]=cc;
     }

     int q=sc.nextInt();
     while(q-->0){
         int l=sc.nextInt();
         int r=sc.nextInt();
         l--;
         r--;
         
    
             if(arr[r]-arr[l]==0){
                 op.write("YES\n");
             }else{
                 op.write("NO\n");
             }

        
     }
  
    
        
  }

  




    static long gcd(long a, long b){
        if(a==0) return b;
        return gcd(b%a,a);
    }
    // static int lcm(int a, int b){
    //     return (a*b)/gcd(a,b);
    // }

    public static void main(String[] args) throws Exception {
        BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out));
        // Reader sc = new Reader();
        Scanner sc= new Scanner(System.in);
        // int t = sc.nextInt();
        // while (t-->0){ne(sc, op);}
        
        ne(sc,op);
           
                   
        op.flush();
    }

    static void print(Object o) {
        System.out.println(String.valueOf(o));
    }
    static int[] toIntArr(String s){
        int[] val= new int[s.length()];
        for(int i=0;i<s.length();i++){
            val[i]=s.charAt(i)-'a';
        }
        return val;
    }
    static void  sort(int[] arr){
        ArrayList<Integer> list= new ArrayList<>();
        for(int i=0;i<arr.length;i++){
            list.add(arr[i]);

        }
        Collections.sort(list);
        for(int i=0;i<arr.length;i++){
            arr[i]=list.get(i);
        }
    }
       static void  sort(long[] arr){
        ArrayList<Long> list= new ArrayList<>();
        for(int i=0;i<arr.length;i++){
            list.add(arr[i]);

        }
        Collections.sort(list);
        for(int i=0;i<arr.length;i++){
            arr[i]=list.get(i);
        }
    }

}

// return -1 to put no ahed in array
class pair {
    int xx;

    int yy;


    pair(int xx, int yy ) {
        this.xx = xx;
        this.yy = yy;
    }
}


class sortY implements Comparator<pair> {
    public int compare(pair p1, pair p2) {
        if (p1.yy > p2.yy) {
            return -1;
        } else if (p1.yy == p2.yy) {
            if (p1.xx > p2.xx) {
                return 1;
            } else if (p1.xx < p2.xx) {
                return -1;
            }
            return 0;

        }
        return 1;
    }
}

class sortX implements Comparator<pair> {
    public int compare(pair p1, pair p2) {
        if (p1.xx > p2.xx) {
            return 1;
        } else if (p1.xx == p2.xx) {
            if (p1.yy > p2.yy) {
                return 1;
            } else if (p1.yy < p2.yy) {
                return -1;
            }
            return 0;

        }
        return -1;
    }
}

class debug {

    static void print1d(long[] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

    }

    static void print1d(int[] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

    }

    static void print1d(boolean[] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.println(i + "= " + arr[i] + " ");
        }

    }

    static void print2d(int[][] arr) {
        System.out.println();
        int n = arr.length;
        int n2 = arr[0].length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n2; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }

    }

    static void print2d(long[][] arr) {
        System.out.println();
        int n = arr.length;
        int n2 = arr[0].length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n2; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }

    }
     static void printPair(ArrayList<pair> list) {
        if(list.size()==0){
            System.out.println("empty list");
            return;
        }
       System.out.println();
       for(int i=0;i<list.size();i++){
          System.out.println(list.get(i).xx+"-"+list.get(i).yy);
       }
    }

}

class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1) {
            if (c == '\n') {
                if (cnt != 0) {
                    break;
                } else {
                    continue;
                }
            }
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');

        if (c == '.') {
            while ((c = read()) >= '0' && c <= '9') {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException {
        if (din == null)
            return;
        din.close();
    }
}
  class MultiTreeSet<E> {
	TreeMap<E, Integer> freqTreeMap = new TreeMap<E, Integer>();
	int size;
 
	public MultiTreeSet() {}
 
	public MultiTreeSet(Collection<? extends E> c) {
		for(E element : c)
			add(element);
	}
    
	public int size() {
		return size;
	}
    public void print(){
        System.out.println(freqTreeMap);
    }
	public void add(E element) {
		Integer freq = freqTreeMap.get(element);
		if(freq==null)
			freqTreeMap.put(element, 1);
		else
			freqTreeMap.put(element,freq+1);
		++size;
	}
 
	public void remove(E element) {
		Integer freq = freqTreeMap.get(element);
		if(freq!=null) {
			if(freq==1)
				freqTreeMap.remove(element);
			else
				freqTreeMap.put(element, freq-1);
			--size;
		}
	}
 
	public int get(E element) {
		Integer freq = freqTreeMap.get(element);
		if(freq==null)
			return 0;
		return freq;
	}
 
	public boolean contains(E element) {
		return get(element)>0;
	}
 
	public boolean isEmpty() {
		return size==0;
	}
 
	public E first() {
		return freqTreeMap.firstKey();
	}
 
	public E last() {
		return freqTreeMap.lastKey();
	}
 
	public E ceiling(E element) {
		return freqTreeMap.ceilingKey(element);
	}
 
	public E floor(E element) {
		return freqTreeMap.floorKey(element);
	}
 
	public E higher(E element) {
		return freqTreeMap.higherKey(element);
	}
 
	public E lower(E element) {
		return freqTreeMap.lowerKey(element);
	}
}
