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

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Amortized analysis

Implementation

Greedy algorithms

Dynamic programming


Solutions:
import os
import sys
from collections import defaultdict, Counter
from io import BytesIO, IOBase
from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)

def sieve():
	global spf, adj, MAXN
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(2, MAXN):
		if i * i > MAXN:
			break
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getdistinctFactorization(n):
	global adj, spf, MAXN
	for i in range(1, n + 1):
		index = 1
		x = i
		if x != 1:
			adj[i].append(spf[x])
		x = x // spf[x]
		while x != 1:
			if adj[i][index - 1] != spf[x]:
				adj[i].append(spf[x])
				index += 1
			x = x // spf[x]

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def main():
	(n, m) = map(int, input().split())
	s = [input().strip() for i in range(n)]
	dp = [0] * m
	for i in range(m - 1, 0, -1):
		for j in range(1, n):
			if s[j - 1][i] == 'X' and s[j][i - 1] == 'X':
				dp[i] = 1
	for i in range(1, m):
		dp[i] += dp[i - 1]
	for i in range(int(input())):
		(xx, yy) = map(int, input().split())
		if xx == yy:
			print('YES')
		else:
			yy -= 1
			xx -= 1
			if dp[yy] - dp[xx] > 0:
				print('NO')
			else:
				print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = iter(sys.stdin.read().splitlines()).__next__
(n, m) = map(int, input().split())
columns = [[] for _ in range(m)]
for _ in range(n):
	for (col, cell) in zip(columns, input()):
		col.append(cell)
prefix_undeterminable_pairs = [0]
for j in range(1, m):
	for i in range(n - 1):
		if columns[j][i] == 'X' and columns[j - 1][i + 1] == 'X':
			prefix_undeterminable_pairs.append(prefix_undeterminable_pairs[-1] + 1)
			break
	else:
		prefix_undeterminable_pairs.append(prefix_undeterminable_pairs[-1])
q = int(input())
a = []
for _ in range(q):
	(x_1, x_2) = map(lambda x: int(x) - 1, input().split())
	a.append('YES' if prefix_undeterminable_pairs[x_1] == prefix_undeterminable_pairs[x_2] else 'NO')
print('\n'.join(a))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
strs = [input() for i in range(n)]
bycol = [0] * m
for i in range(1, n):
	for j in range(1, m):
		if strs[i - 1][j] == 'X' and strs[i][j - 1] == 'X':
			bycol[j] += 1
sums = [bycol[0]]
for i in range(1, m):
	sums.append(sums[-1] + bycol[i])
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == m:
		print('YES')
	else:
		print('YES') if sums[b - 1] - sums[a - 1] == 0 else print('NO')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
B = []
for _ in range(n):
	B.append(list(input().strip()))
best = [-1] * m
j0 = 0

def ok(j):
	if j + 1 >= m:
		return False
	for i in range(1, n):
		if B[i][j] == 'X' and B[i - 1][j + 1] == 'X':
			return False
	return True
for j in range(m):
	j0 = max(j0, j)
	while ok(j0):
		j0 += 1
	best[j] = j0
for nq in range(int(input())):
	(j0, j1) = map(int, input().split())
	j0 -= 1
	j1 -= 1
	if best[j0] < j1:
		print('NO')
	else:
		print('YES')


import io, os
from collections import deque
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def visit(nums, i, j, grid, m, n, flag):
	direc = [[0, 1], [1, 0]]
	queue = deque()
	queue.append([i, j])
	if flag:
		nums[i][j] = j
	else:
		nums[i][j] = 0
	while queue:
		(curri, currj) = queue.popleft()
		for d in range(2):
			newi = curri + direc[d][0]
			newj = currj + direc[d][1]
			if newi < 0 or newi >= m or newj < 0 or (newj >= n):
				continue
			if nums[newi][newj] >= 0:
				continue
			if flag:
				nums[newi][newj] = j
			else:
				nums[newi][newj] = 0
			if grid[newi][newj] == ord('.'):
				queue.append([newi, newj])

def main(t):
	(m, n) = map(int, input().split())
	grid = []
	nums = [[-1 for j in range(n)] for i in range(m)]
	for i in range(m):
		grid.append(input())
	maxnum = [-1] * n
	currmax = [-1] * n
	for j in range(n):
		if grid[0][j] == ord('.'):
			visit(nums, 0, j, grid, m, n, False)
	for j in range(n):
		for i in range(1, m):
			if nums[i][j] == -1:
				if grid[i][j] == ord('.'):
					visit(nums, i, j, grid, m, n, True)
				elif grid[i][j] == ord('X'):
					nums[i][j] = j
		for i in range(m):
			maxnum[j] = max(maxnum[j], nums[i][j])
	currmax[0] = maxnum[0]
	for j in range(1, n):
		currmax[j] = max(currmax[j - 1], maxnum[j])
	q = int(input())
	for _ in range(q):
		(front, rear) = map(int, input().split())
		front -= 1
		rear -= 1
		if currmax[rear] > front:
			print('NO')
		else:
			print('YES')
T = 1
t = 1
while t <= T:
	main(t)
	t += 1


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
MOD = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	(n, m) = map(int, input().split())
	a = []
	s = [0] * m
	for i in range(n):
		a.append(input())
	for i in range(1, n):
		for j in range(1, m):
			if a[i - 1][j] == 'X' and a[i][j - 1] == 'X':
				s[j] += 1
	for i in range(1, m):
		s[i] += s[i - 1]
	q = int(input())
	for i in range(q):
		(x1, x2) = map(int, input().split())
		if s[x2 - 1] - s[x1 - 1] > 0:
			print('NO')
		else:
			print('YES')
main()


import math
import os
import sys
from sys import *
from decimal import *
from io import BytesIO, IOBase
import threading
from itertools import *
from collections import *
from array import *
import random
M = 10 ** 9 + 7
import heapq
import bisect
from functools import lru_cache
from queue import PriorityQueue
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] == key:
			return mid
		if arr[mid] <= key:
			left = mid + 1
		else:
			right = mid - 1
	return -1

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def nge(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def find_shortest_path(graph, start, end, path):
	path = path + [start]
	if start == end:
		return path
	if start not in graph:
		return None
	shortest = None
	for node in graph[start]:
		if node not in path:
			newpath = find_shortest_path(graph, node, end, path)
			if newpath:
				if not shortest or len(newpath) < len(shortest):
					shortest = newpath
	return shortest

def test(n, d):
	a = random.randint(1, n - 2)
	p = pow(a, d, n)
	if p == 1 or p == n - 1:
		return True
	while d != n - 1:
		d *= 2
		p = pow(p, 2, n)
		if p == n - 1:
			return True
	return False

def isprime(n):
	if n == 1:
		return False
	if n == 2:
		return True
	if n == 3:
		return True
	d = n - 1
	while d % 2 == 0:
		d //= 2
	for i in range(5):
		if test(n, d) == False:
			return False
	return True

def muin(a, m):
	(x, y, mo) = (1, 0, m)
	if m == 1:
		return 0
	while m > 0:
		(x, y) = (y, x - a // m * y)
		(a, m) = (m, a % m)
	if x < 0:
		return mo + x
	else:
		return x

def good(l, c):
	ch = chr(c)
	if len(l) == 1:
		return 1 if ch != l[0] else 0
	k = len(l) // 2
	lm = k - l[:k].count(ch) + good(l[k:], c + 1)
	rm = k - l[k:].count(ch) + good(l[:k], c + 1)
	return min(lm, rm)

def facto(fact):
	(fact[0], fact[1]) = (1, 1)
	for i in range(2, 10 ** 6 + 1):
		fact[i] = fact[i - 1] * i % M

def comb(n, r, fact):
	return fact[n] * pow(fact[n - r] * fact[r], M - 2, M) % M

def numberToBase(n, b):
	if n == 0:
		return 0
	digits = []
	while n:
		digits.append(n % b)
		n //= b
	return sum(digits)

def main():
	t = 1
	for tc in range(1, t + 1):
		(n, m) = sep()
		l = []
		for i in range(n):
			l.append(inp())
		p = [0] * (m + 1)
		for i in range(n - 1):
			for j in range(m - 1):
				if l[i + 1][j] == l[i][j + 1] == 'X':
					p[j + 1] = 1
		for i in range(m):
			p[i + 1] += p[i]
		q = inpu()
		for _ in range(q):
			(a, b) = sep()
			if p[b - 1] - p[a - 1] != 0:
				print('NO')
			else:
				print('YES')
main()


import sys
from functools import lru_cache
from collections import defaultdict, deque
from types import GeneratorType
input = sys.stdin.readline

def prefix_sum(arr):
	prefix_arr = [0] * (len(arr) + 1)
	for i in range(len(arr)):
		prefix_arr[i + 1] = prefix_arr[i] + arr[i]
	return prefix_arr

def bfs(x, y, visited, grid, reachable_grid, n, m):
	stack = [(x, y)]
	while stack:
		(x, y) = stack.pop()
		if not visited[x][y]:
			visited[x][y] = True
			if grid[x][y] == '.':
				reachable_grid[x][y] = True
				if y + 1 < m:
					stack.append((x, y + 1))
				if x + 1 < n:
					stack.append((x + 1, y))

def get_reachable_grid(grid, n, m):
	reachable_grid = [[False] * m for _ in range(n)]
	visited = [[False] * m for _ in range(n)]
	y = 0
	for x in range(n):
		if not visited[x][y]:
			if grid[x][y] == '.':
				bfs(x, y, visited, grid, reachable_grid, n, m)
			visited[x][y] = True
	x = 0
	for y in range(m):
		if not visited[x][y]:
			if grid[x][y] == '.':
				bfs(x, y, visited, grid, reachable_grid, n, m)
			visited[x][y] = True
	return reachable_grid

def solve(grid, n, m):
	blocked = [0] * m
	for y in range(1, m):
		for x in range(1, n):
			if grid[x - 1][y] == 'X' and grid[x][y - 1] == 'X':
				blocked[y] = 1
				break
	blocked_prefix = prefix_sum(blocked)
	q = int(input())
	for _ in range(q):
		(y1, y2) = [int(val) - 1 for val in input().split()]
		if blocked_prefix[y2 + 1] - blocked_prefix[y1 + 1] == 0 if y1 != y2 else True:
			sys.stdout.write('YES\n')
		else:
			sys.stdout.write('NO\n')
(n, m) = [int(val) for val in input().split()]
grid = []
for i in range(n):
	row = input()
	grid.append(row)
solve(grid, n, m)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = [int(x) for x in input().split()]
arr = []
for i in range(n):
	arr.append(input())
pre = [0 for x in range(m)]
for j in range(1, m):
	for i in range(n - 1):
		if arr[i][j] == arr[i + 1][j - 1] == 'X':
			pre[j] = pre[j - 1] + 1
			break
	else:
		pre[j] = pre[j - 1]
q = int(input())
for _ in range(q):
	(a, b) = [int(x) - 1 for x in input().split()]
	if pre[a] - pre[b]:
		sys.stdout.write('NO\n')
	else:
		sys.stdout.write('YES\n')


import sys
input = sys.stdin.readline
print = sys.stdout.write
(n, m) = map(int, input().split())
s = [input() for i in range(n)]
f = [0, 0]
acc = 0
for i in range(1, m):
	for j in range(n - 1):
		if s[j][i] == 'X' and s[j + 1][i - 1] == 'X':
			acc += 1
			break
	f.append(acc)
k = int(input())
for i in range(k):
	(a, b) = map(int, input().split())
	print('YES\n' if f[b] - f[a] == 0 else 'NO\n')


import sys
from sys import stdin
(n, m) = map(int, stdin.readline().split())
a = [stdin.readline()[:-1] for i in range(n)]
b = [0] * m
for j in range(m - 1):
	for i in range(1, n):
		if a[i][j] == a[i - 1][j + 1] == 'X':
			b[j + 1] = 1
for i in range(m - 1):
	b[i + 1] += b[i]
ANS = []
q = int(stdin.readline())
for loop in range(q):
	(x, y) = map(int, stdin.readline().split())
	x -= 1
	y -= 1
	if b[x] == b[y]:
		ANS.append('YES')
	else:
		ANS.append('NO')
print('\n'.join(ANS))


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
G = []
for i in range(0, n):
	G.append(sys.stdin.readline().strip())
F = []
for j in range(0, m - 1):
	v = False
	for i in range(0, n - 1):
		if G[i + 1][j] == 'X' and G[i][j + 1] == 'X':
			v = True
	if v == True:
		F.append(j)
Q = int(sys.stdin.readline().strip())
for q in range(0, Q):
	(x1, x2) = list(map(int, sys.stdin.readline().strip().split()))
	(x1, x2) = (x1 - 1, x2 - 1)
	v = True
	for f in F:
		if x1 <= f < x2:
			v = False
	if v == True:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
s = [input()[:-1] for i in range(n)]
q = int(input())
queries = [list(map(int, input().split())) for i in range(q)]
a = [0] * m
for i in range(1, n):
	for j in range(m - 1):
		if s[i][j] == 'X' and s[i - 1][j + 1] == 'X':
			a[j] += 1
ru = [0] * (m + 1)
for i in range(m):
	ru[i + 1] = ru[i] + a[i]
ans = []
for (l, r) in queries:
	l -= 1
	r -= 1
	if ru[r] - ru[l] > 0:
		ans.append('NO')
	else:
		ans.append('YES')
print('\n'.join(ans))


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
from collections import Counter as cc

def isprime(n):
	if n % 2 == 0 and n > 2 or n == 1:
		return 0
	else:
		s = int(n ** 0.5) + 1
		for i in range(3, s, 2):
			if n % i == 0:
				return 0
		return 1
tc = 1
for test in range(1, tc + 1):
	(n, m) = inp()
	a = [input() for i in range(n)]
	d = [0] * (m + 1)
	for i in range(1, m):
		d[i + 1] += d[i]
		for j in range(n - 1):
			if a[j][i] == 'X' and a[j + 1][i - 1] == 'X':
				d[i + 1] += 1
	for q in range(int(input())):
		(x1, x2) = inp()
		if d[x1] == d[x2]:
			print('YES')
		else:
			print('NO')


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp_vars_int = lambda : map(int, input().split())
inp_list_int = lambda : list(map(int, input().split()))
(n, m) = inp_vars_int()
cols = [[0 for _ in range(n)] for _ in range(m)]
for i in range(n):
	r = input()
	for (j, c) in enumerate(r):
		if c == 'X':
			cols[j][i] = 1
cols_undef = set()
prsum = [0]
for j in range(1, m):
	is_undef = False
	for i in range(1, n):
		if cols[j][i - 1] and cols[j - 1][i]:
			is_undef = True
			cols_undef.add(j)
			break
	prsum.append(prsum[-1] + is_undef)
q = int(input())
for _ in range(q):
	(x1, x2) = inp_vars_int()
	res = True
	num_undef = prsum[x2 - 1] - prsum[x1 - 1]
	if num_undef:
		res = False
	print('yes' if res else 'no')


import sys
input = sys.stdin.readline
print = sys.stdout.write
(a, b) = map(int, input().split())
data = []
for i in range(a):
	data.append(input().strip())
dp = [0 for i in range(b)]
for i in range(1, a):
	for p in range(1, b):
		if data[i][p - 1] == 'X' and data[i - 1][p] == 'X':
			dp[p] = 1
su = []
suz = 0
for i in dp:
	suz += i
	su.append(suz)
for i in range(int(input())):
	(q, w) = map(int, input().split())
	print(('YES' if su[q - 1] == su[w - 1] else 'NO') + '\n')


import collections as cc
import math as mt
import sys
I = lambda : list(map(int, input().split()))
input = sys.stdin.readline
(n, m) = I()
ar = [list(input().strip()) for i in range(n)]
temp = [0] * (m + 1)
for j in range(m):
	for i in range(n):
		if i - 1 >= 0 and j + 1 < m:
			if ar[i][j] == 'X' and ar[i - 1][j + 1] == 'X':
				temp[j] = 1
for k in range(1, m):
	temp[k] += temp[k - 1]
(q,) = I()
for tq in range(q):
	(x, y) = I()
	x -= 1
	y -= 1
	if x == y:
		print('YES')
	elif temp[y - 1] - temp[x - 1]:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
G = [input() for _ in range(N)]
from bisect import bisect_left
X = []
for x in range(M - 1):
	for y in range(N - 1):
		if G[y + 1][x] == G[y][x + 1] == 'X':
			X.append(x)
			break
O = []
for _ in range(int(input())):
	(x1, x2) = map(int, input().split())
	if x1 == x2:
		O.append('YES')
		continue
	x1 -= 1
	x2 -= 1
	i = bisect_left(X, x1)
	if i < len(X) and X[i] < x2:
		O.append('NO')
	else:
		O.append('YES')
print('\n'.join(O))


import sys
import bisect
input = sys.stdin.readline

def SieveOfEratosthenes(n):
	arr = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	for p in range(n + 1):
		if prime[p]:
			arr.append(p)
	return arr

def solve():
	(n, m) = map(int, input().split())
	a = []
	for _ in range(n):
		a.append(input())
	v = []
	for j in range(1, m):
		for i in range(1, n):
			if a[i][j - 1] == 'X' and a[i - 1][j] == 'X':
				v.append(j)
				break
	v.append(m)
	q = int(input())
	for i in range(q):
		(x, y) = map(int, input().split())
		lower_bound = bisect.bisect_left(v, x, 0, len(v))
		if v[lower_bound] < y:
			print('NO')
		else:
			print('YES')
t = 1
for _ in range(t):
	k = solve()


inf = float('inf')
import sys
import pprint
import logging
from logging import getLogger
import array

def input():
	return sys.stdin.readline().rstrip('\r\n')

def maps():
	return [int(i) for i in input().split()]
logging.basicConfig(format='%(message)s', level=logging.WARNING)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)

def debug(msg, *args):
	logger.info(f'{msg}={pprint.pformat(args)}')
from bisect import bisect_left

def solve():
	(r, c) = maps()
	A = [input() for _ in range(r)]
	pref = [0] * c
	for C in range(1, c):
		for R in range(1, r):
			if A[R][C - 1] == A[R - 1][C] == 'X':
				pref[C] = 1
	for i in range(1, c):
		pref[i] += pref[i - 1]
	for _ in range(*maps()):
		(x, y) = map(lambda x: int(x) - 1, input().split())
		if x == y:
			print('YES')
			continue
		print('NO' if pref[y] - pref[x] else 'YES')
solve()


from sys import stdin
input = stdin.readline

def answer():
	count = [0 for i in range(m + 1)]
	for i in range(1, n):
		for j in range(1, m):
			if a[i - 1][j] == 'X' and a[i][j - 1] == 'X':
				count[j + 1] += 1
	for i in range(1, m + 1):
		count[i] += count[i - 1]
	for q in range(int(input())):
		(x1, x2) = map(int, input().split())
		if count[x2] == count[x1]:
			print('YES')
		else:
			print('NO')
for T in range(1):
	(n, m) = map(int, input().split())
	a = [input().strip() for i in range(n)]
	answer()


def main():
	(n, m) = readIntArr()
	fill = ord('X')
	grid = []
	for _ in range(n):
		arr = input()
		arr2 = []
		for i in range(m):
			if arr[i] == fill:
				arr2.append(1)
			else:
				arr2.append(0)
		grid.append(arr2)
	colSum = [0] * m
	for i in range(n - 1):
		for j in range(m - 1):
			if grid[i + 1][j] == grid[i][j + 1] == 1:
				colSum[j] += 1
	p = colSum.copy()
	for i in range(1, m):
		p[i] += p[i - 1]

	def query(l, r):
		if l == r:
			return 0
		elif l - 1 >= 0:
			return p[r - 1] - p[l - 1]
		else:
			return p[r - 1]
	allans = []
	for _ in range(int(input())):
		(l, r) = readIntArr()
		l -= 1
		r -= 1
		if query(l, r) > 0:
			allans.append('nO')
		else:
			allans.append('yES')
	multiLineArrayPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(i1, j1, i2, j2):
	print('! {} {} {} {}'.format(i1, j1, i2, j2))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
for _abc in range(1):
	main()


def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import sys, os, copy, string, math, time, functools, fractions
from io import BytesIO, IOBase
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, chain, combinations, groupby
from operator import itemgetter
from types import GeneratorType
from typing import Iterable, TypeVar, Union
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def main():
	(n, m) = LI()
	inp = []
	for i in range(n):
		inp.append(I())
	color = [0] * m
	for i in range(1, m):
		check = True
		for j in range(1, n):
			if inp[j][i - 1] == 'X' and inp[j - 1][i] == 'X':
				check = False
		if not check:
			color[i] = color[i - 1] + 1
		else:
			color[i] = color[i - 1]
	q = II()
	for i in range(q):
		(x1, x2) = LI()
		if color[x1 - 1] == color[x2 - 1]:
			print('YES')
		else:
			print('NO')
for _ in range(1):
	main()


import sys, os, io
input = sys.stdin.readline
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
(n, m) = li()
store = [0 for i in range(n)]
for i in range(n):
	store[i] = input().strip()
p = [0 for i in range(m)]
for i in range(m - 1):
	for j in range(n - 1):
		if store[j][i + 1] == 'X' and store[j + 1][i] == 'X':
			p[i] = 1
for i in range(1, m):
	p[i] = p[i] + p[i - 1]
m = ii()
for q in range(m):
	(x, y) = li()
	x -= 1
	y -= 1
	if y == x:
		print('YES')
	elif x != 0:
		if p[y - 1] - p[x - 1] >= 1:
			print('NO')
		else:
			print('YES')
	elif p[y - 1] >= 1:
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
(n, m) = invr()
l = []
undecide = set()
for i in range(n):
	temp = insr()
	l.append(temp)
for i in range(1, n):
	for j in range(1, m):
		if l[i][j - 1] == 'X' and l[i - 1][j] == 'X':
			undecide.add(j)
q = inp()
for i in range(q):
	(a, b) = invr()
	a -= 1
	b -= 1
	flag = 1
	for j in undecide:
		if j > a and j <= b:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from itertools import permutations
from collections import *
from collections import deque
from operator import itemgetter, attrgetter
from decimal import *
import bisect
import math
import heapq as hq
MOD = 10 ** 9 + 7

def is_prime(n):
	if n == 2 or n == 3:
		return True
	if n < 2 or n % 2 == 0:
		return False
	if n < 9:
		return True
	if n % 3 == 0:
		return False
	r = int(n ** 0.5)
	f = 5
	while f <= r:
		if n % f == 0:
			return False
		if n % (f + 2) == 0:
			return False
		f += 6
	return True

def pow(a, b, m):
	ans = 1
	while b:
		if b & 1:
			ans = ans * a % m
		b //= 2
		a = a * a % m
	return ans

def ispalindrome(s):
	if s[:] == s[::-1]:
		return 1
	return 0
dp = []
limit = []
v = []

def dpdfs(u, t=-1):
	dp[0][u] = 0
	dp[1][u] = 0
	for i in v[u]:
		if i == t:
			continue
		if dp[1][i] == -1:
			dpdfs(i, u)
		dp[0][u] += max(abs(limit[0][u] - limit[1][i]) + dp[1][i], abs(limit[0][u] - limit[0][i]) + dp[0][i])
		dp[1][u] += max(abs(limit[1][u] - limit[1][i]) + dp[1][i], abs(limit[1][u] - limit[0][i]) + dp[0][i])
vis = []
f = 0
from math import factorial as fact
from queue import PriorityQueue

def z_algorithm(s):
	res = [0] * len(s)
	res[0] = len(s)
	(i, j) = (1, 0)
	while i < len(s):
		while i + j < len(s) and s[j] == s[i + j]:
			j += 1
		res[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < len(s) and k + res[k] < j:
			res[i + k] = res[k]
			k += 1
		(i, j) = (i + k, j - k)
	return res

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a / gcd(a, b) * b

def gcdExtended(a, b):
	if a == 0:
		return (b, 0, 1)
	(gcd, x1, y1) = gcdExtended(b % a, a)
	x = y1 - b // a * x1
	y = x1
	return (gcd, x, y)
import re
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
cnt = [[0 for i in range(m)] for i in range(n)]
val = [0 for i in range(m)]
for i in range(1, n):
	for j in range(1, m):
		if l[i - 1][j] == 'X' and l[i][j - 1] == 'X':
			cnt[i][j] = 1
for i in range(1, m):
	for j in range(n):
		val[i] += cnt[j][i]
	val[i] += val[i - 1]
q = int(input())
for i in range(q):
	(x1, x2) = map(int, input().split())
	if val[x2 - 1] - val[x1 - 1] == 0:
		print('YES')
	else:
		print('NO')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def hnbhai(tc):
	(n, m) = sd()
	mat = []
	for i in range(n):
		mat.append(sa())
	pre = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if mat[i][j] != '.':
				if i - 1 >= 0 and j - 1 >= 0:
					if mat[i - 1][j] == 'X' and mat[i][j - 1] == 'X':
						pre[i][j] = 1
				continue
			if i - 1 >= 0 and j - 1 >= 0:
				if mat[i - 1][j] == 'X' and mat[i][j - 1] == 'X':
					pre[i][j] = 1
	col = [0] * (m + 1)
	for j in range(m):
		x = 0
		for i in range(n):
			if pre[i][j] == 1:
				x = 1
				break
		col[j] = x
	for i in range(1, m + 1):
		col[i] += col[i - 1]
	for i in range(sb()):
		(x, y) = sd()
		x -= 1
		y -= 1
		if x == y:
			print('YES')
			continue
		if col[y] - col[x] != 0:
			print('NO')
			continue
		print('YES')
for _ in range(1):
	hnbhai(_ + 1)


import sys
inp = sys.stdin.readline
(n, m) = map(int, inp().split())
grid = [inp() for _ in range(n)]
prefix_sums = [0 for _ in range(m + 1)]
for i in range(n - 1):
	for j in range(m - 1):
		if grid[i + 1][j] == grid[i][j + 1] == 'X':
			prefix_sums[j + 1] = 1
for j in range(m):
	prefix_sums[j + 1] += prefix_sums[j]
for _ in range(int(inp())):
	(x1, x2) = map(int, inp().split())
	print('YES') if prefix_sums[x2 - 1] - prefix_sums[x1 - 1] == 0 else print('NO')


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
mod1 = 998244353
(n, m) = il()
a = []
for i in range(n):
	a.append(list(ip()))
pre = [0 for i in range(m + 1)]
for i in range(1, m):
	for j in range(1, n):
		if a[j - 1][i] == 'X' and a[j][i - 1] == 'X':
			pre[i] += 1
q = ii()
for i in range(1, m + 1):
	pre[i] += pre[i - 1]
for i in range(q):
	(x, y) = il()
	if x == y:
		print('YES')
		continue
	t = pre[y - 1] - pre[x - 1]
	if t > 0:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
t = 1
for _ in range(t):
	(n, m) = I()
	grid = [list(input().strip()) for i in range(n)]
	ans = [0] * (m + 1)
	for j in range(m - 1):
		for i in range(1, n):
			if grid[i][j] + grid[i - 1][j + 1] == 'XX':
				ans[j] = 1
				break
	for i in range(1, m):
		ans[i] += ans[i - 1]
	ans[-1] = 0
	(q,) = I()
	for i in range(q):
		(l, r) = I()
		an = 'YES'
		if r > l:
			cnt = ans[r - 2] - ans[l - 2]
			if cnt:
				an = 'NO'
		print(an)


from sys import *
input = stdin.readline
import threading
from bisect import *
import math
from collections import *
import operator
from heapq import *
from itertools import *
inf = 10 ** 19
mod = 10 ** 9 + 7
MOD = 998244353
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
dx = [-1, 0]
dy = [0, -1]
setrecursionlimit(200005)

def asc(c):
	return ord(c) - 97 + 1
(n, m) = map(int, input().split())
arr = [list(input().strip()) for _ in range(n)]
pro = set()
for i in range(1, n):
	for j in range(1, m):
		if arr[i - 1][j] == 'X' and arr[i][j - 1] == 'X':
			pro.add(j + 1)
pro = sorted(pro)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('NO' if bisect_right(pro, b) - bisect_left(pro, a + 1) else 'YES')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = [list(input())[:-1] for _ in range(n)]
table = [0] * (m + 1)
for i in range(n - 1):
	for j in range(m - 1):
		if a[i + 1][j] == a[i][j + 1] == 'X':
			table[j + 1] = 1
for j in range(m):
	table[j + 1] += table[j]
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	if table[r - 1] - table[l - 1] == 0:
		print('YES')
	else:
		print('NO')


import collections
import math
import itertools
import sys
import time
import random

def fast_input():
	return sys.stdin.readline().strip()
input = fast_input

def ints_input():
	return list((int(x) for x in input().split()))

def int_input():
	return int(input())

def is_prime(s):
	for i in range(2, s):
		if i * i > s:
			return True
		if s % i == 0:
			return False

class MinMaxIntervalLookup:

	def __init__(self, array, fn):
		self._levels = []
		self._levels.append(list(array))
		self._fn = fn
		while True:
			next_layer = []
			for (i, val) in enumerate(self._levels[-1]):
				if i % 2 == 0:
					if i == len(self._levels[-1]) - 1:
						next_layer.append(i)
					else:
						next_layer.append(fn(val, self._levels[-1][i + 1]))
			self._levels.append(next_layer)
			if len(next_layer) == 1:
				break

	def lookup(self, left, right):
		assert 0 <= left
		assert left <= right
		assert right <= len(self._levels[0])
		layer = 0
		index = left
		while index % 2 == 0 and left + 2 ** (layer + 1) - 1 <= right:
			layer += 1
			index = index // 2
		end = left + 2 ** layer - 1
		val = self._levels[layer][index]
		if end == right:
			return val
		else:
			return self._fn(val, self.lookup(end + 1, right))

def solve():
	(n, m) = ints_input()
	arr = [[None for _ in range(m)] for _ in range(n)]
	bad_cols = [0 for _ in range(m)]
	for j in range(n):
		line = input()
		for (i, c) in enumerate(line):
			if c == 'X':
				arr[j][i] = 1
			else:
				arr[j][i] = 0
			if j > 0 and i > 0 and arr[j - 1][i] and arr[j][i - 1]:
				bad_cols[i] = 1
	lookup = MinMaxIntervalLookup(bad_cols, max)
	queries = int_input()
	for _ in range(queries):
		(left, right) = ints_input()
		if left == right:
			print('YES')
			continue
		ans = lookup.lookup(left, right - 1)
		if ans == 1:
			print('NO')
			continue
		else:
			print('YES')
			continue
if False:
	for _ in range(int_input()):
		solve()
else:
	solve()