#include <iostream>
using namespace std;
int f[20005];
int n, m, q, a, b, c, d;
void init()
{
for (int i = 1; i <= 20000; i++)
f[i] = i;
}
int findr(int x)
{
if (f[x] != x)
f[x] = findr(f[x]); // 路径压缩
return f[x];
}
void maset(int a, int b)
{
int fa = findr(a);
int fb = findr(b);
if (fa != fb)
f[fa] = fb;
}
int main()
{
init();
scanf("%d %d", &n, &m);
while (m--)
{
scanf("%d %d", &a, &b);
maset(a, b);
}
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";
scanf("%d", &q);
while (q--)
{
scanf("%d %d", &c, &d);
if (findr(c) == findr(d))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}