var
n,m,q,b,c,g,d,e:longint;
a:array[1..20000]of integer;
begin
assign(input,'relations.in');
reset(input);
assign(output,'relations.out');
rewrite(output);
read(n,m);
for m:=1 to m do
begin
read(b,c);
if (a[b]<>0)and(a[c]=0) then a[c]:=a[b];
if (a[c]<>0)and(a[b]=0) then a[b]:=a[c];
if (a[b]=0)and(a[c]=0) then
begin
inc(g);
a[c]:=g;
a[b]:=g;
end;
if (a[b]<>0)and(a[c]<>0)and(a[b]<>a[c]) then
begin
e:=a[c];
for d:=1 to n do
if a[d]=e then a[d]:=a[b];
end;
end;
{for n:=1 to n do
writeln(a[n]);
writeln;}
read(q);
for q:=1 to q do
begin
read(b,c);
if (b=0)or(c=0) then
begin
writeln('Yes');
exit;
end;
if (a[b]=a[c])and(a[b]<>0) then writeln('Yes')
else writeln('No');
end;
close(input);close(output);
end.