program cojs259;
var
fa:array[1..20000]of longint;
i,n,m,t1,t2,x,y:longint;
function find(x:longint):longint;
var
t,p,q:longint;
begin
if fa[x]<0 then exit(x);
q:=x;
while fa[q]>0 do
q:=fa[q];
p:=x;
while fa[p]>0 do
begin
t:=p; fa[t]:=q; p:=fa[p];
end;
exit(q);
end;
procedure union(x,y:longint);
var
t:longint;
begin
t:=fa[x]+fa[y];
if fa[x]>fa[y] then
begin
fa[x]:=y;
fa[y]:=t;
end else begin
fa[y]:=x;
fa[x]:=t;
end;
end;
begin
assign(input,'relations.in');reset(input);
assign(output,'relations.out');rewrite(output);
readln(n,m);
for i:=1 to n do
fa[i]:=-1;
for i:=1 to m do
begin
readln(x,y);
t1:=find(x);
t2:=find(y);
if t1<>t2 then union(t1,t2);
end;
readln(m);
for i:=1 to m do
begin
readln(x,y);
t1:=find(x);
t2:=find(y);
if t1=t2 then writeln('Yes') else writeln('No');
end;
close(input);close(output);
end.