// Slower C++ solution:
#include <iostream>

#include <vector>

#include <queue>



using namespace std;



struct Node {

    int color = 0;

    vector<int> next;

} node[100000];



int main() {

    int n, m, q, t1, t2;



    cin >> n >> m;

    for (int i = 0; i < m; i++) {

        cin >> t1 >> t2;

        node[t1].next.push_back(t2);

        node[t2].next.push_back(t1);

    }



    int color = 1;

    queue<int> que;

    while (1) {

        int start = -1;

        for (int i = 0; i < n; i++) {

            if (node[i].color == 0) {

                start = i;

                break;

            }

        }

        if (start == -1) {

            break;

        }

        

        node[start].color = color;

        que.push(start);

        while (!que.empty()) {

            int temp = que.front();

            int size = node[temp].next.size();

            for (int i = 0; i < size; i++) {

                if (node[node[temp].next[i]].color == 0) {

                    node[node[temp].next[i]].color = color;

                    que.push(node[temp].next[i]);

                }

            }

            que.pop();

        }

        color++;

    }



    cin >> q;

    for (int i = 0; i < q; i++) {

        cin >> t1 >> t2;

        if (node[t1].color == node[t2].color && node[t1].color > 0 && node[t2].color > 0) {

            cout << "yes" << endl;

        }

        else {

            cout << "no" << endl;

        }

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.351634525214344x):
#include <map>

#include <set>

#include <list>

#include <cmath>

#include <deque>

#include <queue>

#include <stack>

#include <cstdio>

#include <string>

#include <vector>

#include <complex>

#include <cstdlib>

#include <cstring>

#include <numeric>

#include <utility>

#include <iostream>

#include <algorithm>

#include <functional>

#include <unordered_map>

#include <unordered_set>



using namespace std;



#define ll long long

#define ull unsigned long long

#define INF (1 << 30)

#define LLINF (1LL << 62)

#define MOD7 1000000007

#define MOD9 1000000009

#define eps 1e-9

#define P pair<int, int>

#define pii pair<int, int>

#define pll pair<ll, ll>

#define pul pair<ull, ull>

#define all(a) (a).begin(), (a).end()

#define FOR(i,a,b) for (int i=(a);i<(b);++i)

#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)

#define REP(i,n) for (int i=0;i<(n);++i)

#define RREP(i,n) for (int i=(n)-1;i>=0;--i)



void YES() { cout << "YES\n"; }

void NO() { cout << "NO\n"; }

void Yes() { cout << "Yes\n"; }

void No() { cout << "No\n"; }

void yes() { cout << "yes" << endl; }

void no() { cout << "no" << endl; }



int n, m;

vector<vector<int>> g;

int color[100000];



void dfs(int s, int col) {

	if (color[s] > 0)

		return;

	color[s] = col;



	for (int i = 0; i < g[s].size(); ++i) {

		dfs(g[s][i], col);

	}

}



int main() {

	int q, s, t;

	cin >> n >> m;

	g.resize(n);

	while (m--) {

		cin >> s >> t;

		g[s].push_back(t);

		g[t].push_back(s);

	}



	int col = 1;

	for (int i = 0; i < n; ++i) {

		dfs(i, col++);

	}



	cin >> q;

	while (q--) {

		cin >> s >> t;

		if (color[s] == color[t])

			yes();

		else

			no();

	}



	return 0;

}