Chef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries.  For this he has came up with an idea - he will group together all those orders which have to be delivered in nearby areas. 

In particular, he has identified certain bidirectional roads which he calls as fast roads. They are short and usually traffic free, so the fast travel is possible along these roads. His plan is that he will send orders to locations A and B together if and only if it is possible to travel between A and B using only fast roads. Your task is, given the configuration of fast roads, identify which orders are to be sent together.

-----Input-----
First line of input contains an integer T, the number of test cases. Then T test cases follow. First line of each test case contains two space separated integers N and M, denoting number of locations and the number of fast roads. Then M lines follow each containing two space separated integers A and B, denoting that there is a fast road between locations A and B. Assume that locations are indexed by numbers from 0 to N-1. 

Next line contains an integer Q denoting the number of queries. Each of the next Q lines contain two integers X and Y. For each query you have to find out if orders meant for locations X and Y are to be sent together or not.

Note that there might be multiple fast roads between same pair of locations, also there might be a fast road that links a location to itself.

-----Output-----
For each test case print Q lines - one for each query. Output "YO" if the orders are to be 
delivered together and "NO" otherwise (quotes for clarity).

-----Constraints-----
1 ≤ T ≤ 100
1 ≤ N ≤ 100
1 ≤ M ≤ 1000
0 ≤ A, B, X, Y ≤ N-1
1 ≤ Q ≤ 3000

-----Example-----
Input:
1
4 2
0 1
1 2
3
0 2
0 3
2 1

Output:
YO
NO
YO

-----Warning!-----
There are large input and output files in this problem. Make sure you use fast enough I/O methods.

Starter code:

Solutions:
# cook your dish here
from sys import stdin, stdout
from math import ceil


def solve():
    for _ in range(int(input())):
        n, m = map(int, stdin.readline().split())
        par = [i for i in range(n)]
        for i in range(m):
            ta, tb = map(int, stdin.readline().strip().split())
            a, b = min(ta, tb), max(ta, tb)
            for j in range(n):
                if par[j] == par[b] and j != b:
                    par[j] = par[a]
            par[b] = par[a]

        q = int(input())
        while q:
            q -= 1
            x, y = map(int, stdin.readline().split())
            if par[x] == par[y]:
                print("YO")
            else:
                print("NO")


def __starting_point():
    solve()

__starting_point()

t=int(input())
for i in range(0,t):
	n,m=map(int,input().split())
	l=[0]*n
	for j in range(0,n):
		l[j]=j
	for j in range(0,m):
		a,b=map(int,input().split())
		if(l[a]<l[b]):
			temp=l[b]
			for p in range(0,n):
				if(l[p]==temp):
					l[p]=l[a]
		elif(l[b]<l[a]):
			temp=l[a]
			for p in range(0,n):
				if(l[p]==temp):
					l[p]=l[b]
	q=int(input())
	for p in range(0,q):
		x,y=map(int,input().split())
		if(l[x]==l[y]):
			print("YO")
		else:
			print("NO")
		





           


import sys

sys.setrecursionlimit(10000)



def dfs(n):
    ans = set()
    queue = [n]
    bool[n] = True
    ans.add(n)
    while queue!=[]:
        z = queue.pop(0)
        ans.add(z)
        for j in hash[z]:
            if bool[j] == False:
                bool[j] = True
                queue.append(j)

    return ans







from collections import defaultdict

t = int(input())

for _ in range(t):

    ans = []
    hash = defaultdict(list)
    n,m = map(int,sys.stdin.readline().strip().split())
    for i in range(m):
        a,b = map(int,sys.stdin.readline().strip().split())
        hash[a].append(b)
        hash[b].append(a)

    for i in range(n):
        bool = [False]*n
        z = dfs(i)
        hash[i] = z



    q = int(input())
    for i in range(q):

        a,b = map(int,sys.stdin.readline().strip().split())

        dfs(a)
        # print(bool)
        if b in hash[a]:
            z = 'YO'
            sys.stdout.write(z)
            print()

        else:
            z = 'NO'
            sys.stdout.write(z)
            print()




from collections import defaultdict
 
class Graph:
 
    def __init__(self,vertices):
 
        self.graph = defaultdict(list)
        self.DFSList = defaultdict(list)
        
        for i in range(0,vertices):
        	self.graph[i]=[]
        	self.DFSList[i]=[]
 	

    def addEdge(self,u,v):
        if u!=v:
        	self.graph[u].append(v)
        	self.graph[v].append(u)
        	
    def DFSUtil(self,v,visited,n):
 
        visited[v]= True
        self.DFSList[n].append(v)
       
        
        for i in self.graph[v]:
            if visited[i] == False:
                self.DFSUtil(i, visited,n)
 
    def DFS(self,v):
 
        visited = [False]*(len(self.graph))
        self.DFSUtil(v,visited,v)
 
t=int(input())
for z in range(0,t):
	n,m=map(int,input().split())
	g = Graph(n)

	for M in range(0, m):
		u,v = map(int,input().split())
		g.addEdge(u,v)
	
	for i in range(0,n):
		g.DFS(i)
		
	q = int(input())
	for Q in range(0, q):
		u,v = map(int,input().split())
		if v in g.DFSList[u]:
			print("YO")
		else:
			print("NO")