// 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.314137063649572x):
#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" << endl; }

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

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

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

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

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



template<class T>

class UnDirectedGraph {

public:

	class Edge {

	public:

		int to;

		T cost;



		Edge(int t, T c) : to(t), cost(c) {}



		bool operator<(const Edge& right) const {

			return cost == right.cost ? to < right.to : cost < right.cost;

		}

	};



	vector<vector<Edge>> G;

	int V;



	UnDirectedGraph(int n = 0) {

		resize(n);

	}



	void resize(int n) {

		V = n;

		G.resize(n);

	}



	void addEdge(int from, int to, T cost = 0) {

		int v = max(from, to);

		if (v >= V)

			resize(v + 1);

		G[from].push_back(Edge(to, cost));

		G[to].push_back(Edge(from, cost));

	}



	vector<int> visit;

	int col = 0;

	void dfs(int s) {

		//vector<int> visit(V);

		visit.resize(V);

		col++;

		calcDfs(visit, s);

	}



	void calcDfs(vector<int>& visit, int s) {

		if (visit[s])

			return;



		//visit[s] = 1;

		visit[s] = col;

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

			calcDfs(visit, G[s][i].to);

		}

	}



	vector<int> bfs(int s) {

		vector<int> dist(V);

		queue<int> que;



		fill(dist.begin(), dist.end(), -1);

		dist[s] = 0;

		que.push(s);

		while (!que.empty()) {

			int from = que.front();

			que.pop();

			for (int i = 0; i < G[from].size(); ++i) {

				int to = G[from][i].to;

				if (dist[to] != -1)

					continue;

				dist[to] = dist[from] + 1;

				que.push(to);

			}

		}



		return dist;

	}

};



int main() {

	int n, m, from, to;

	cin >> n >> m;

	UnDirectedGraph<int> g(n);

	while (m--) {

		cin >> from >> to;

		g.addEdge(from, to);

	}

	

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

		g.dfs(i);



	int q;

	cin >> q;

	while (q--) {

		cin >> from >> to;

		if (g.visit[from] == g.visit[to])

			yes();

		else

			no();

	}



	return 0;

}