#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int p[30000];
int rank1[30000];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline void make_set(int xx){
p[xx]=xx;
rank1[xx]=0;
}
int find_set(int xx){
if (xx!=p[xx])
p[xx]=find_set(p[xx]);
return p[xx];
}
void union1(int x,int y){
x=find_set(x);
y=find_set(y);
if (x!=y)
if (rank1[x]>rank1[y])
p[y]=x;
else
{
p[x]=y;
if (rank1[x]==rank1[y])
rank1[y]=rank1[y]+1;
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
make_set(i);
int a,b;
for(int i=1;i<=m;i++){
a=read(),b=read();
union1(a,b);
}
cin>>k;
for(int i=1;i<=k;i++){
a=read(),b=read();
if(find_set(a)==find_set(b))
printf("Yes\n");
else
printf("No\n");
}
}