#include <iostream>
#include <cstdio>
using namespace std;
int father[20010]; //father[i]表示i的父亲
int Find(int a) //查找其父亲并压缩路径
{
if(father[a] != a)
father[a] = Find(father[a]);
return father[a];
}
int main()
{
freopen("relations.in","r",stdin);
freopen("relations.out","w",stdout);
int N,M;
int a,b;
scanf("%d%d",&N,&M);
//给每个元素建立一个集合
for(int i = 1 ; i <= N ; ++i)
father[i] = i;
//合并
for(int i = 0 ; i < M ; ++i)
{
scanf("%d%d",&a,&b);
a = Find(a);
b = Find(b);
father[a] = b;
}
//查询
scanf("%d",&M);
while(M--)
{
scanf("%d%d",&a,&b);
a = Find(a);
b = Find(b);
if(a == b)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}