//============================================================================
// Name        : Graph.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

struct Node{
	int id;
	vector<int> adjNodes;
	bool isFound;
	int discover_time;
	int finish_time;
	int distance;
	int group_id;
};

class Graph{
public:
	vector<Node> nodeList;
	map<int, vector<Node*> > distanceMap;
	Graph():nodeList(), distanceMap(){}
	Graph(int n):nodeList(), distanceMap(){
		for(int i=0; i<n; i++){
			vector<int> empty_vec;
			Node node = {i, empty_vec, false, -1, -1, -1, -1};
			nodeList.push_back(node);
		}
	}

	void insert(Node& i){
		nodeList.push_back(i);
	}

	void SearchDepthFirst(int source_id, int& timer, int group_id){
		Node& source_node = nodeList.at(source_id);
		source_node.isFound = true;
		source_node.discover_time = timer;
		for(int i=0; i<source_node.adjNodes.size(); i++){
			if(nodeList.at(source_node.adjNodes.at(i)).isFound == false){
				timer ++;
				nodeList.at(source_node.adjNodes.at(i)).isFound = true;
				nodeList.at(source_node.adjNodes.at(i)).discover_time = timer;
				SearchDepthFirst(source_node.adjNodes.at(i), timer, group_id);
				nodeList.at(source_node.adjNodes.at(i)).finish_time = timer;
				nodeList.at(source_node.adjNodes.at(i)).group_id = group_id;
			}
		}
		timer++;

		source_node.finish_time = timer;
	}

	void SearchDepthFirstAll(int& timer){
		int group_id = 0;
		for(int i=0; i<nodeList.size(); i++){
			if(nodeList.at(i).isFound == false){
				nodeList.at(i).group_id = group_id;
				SearchDepthFirst(i, timer, group_id);
				timer++;
				group_id++;
			}
		}
	}

	void writeSearchResult(){
		for(int i=0; i<nodeList.size(); i++){
			cout << nodeList.at(i).id << " " << nodeList.at(i).group_id << "\n";
		}
	}


	void addDistance(){
		vector<Node*> vec;
		vec.push_back(&nodeList.at(0));
		distanceMap[0] =vec;
		int cur_distance=0;

		while(cur_distance < nodeList.size()){
			vector<Node*>& vec_p_node = distanceMap[cur_distance];
			vector<Node*> empty_vec;
			distanceMap[cur_distance+1] = empty_vec;
			for(int i=0; i<vec_p_node.size(); i++){
				vector<int>& adjNodes = vec_p_node.at(i)->adjNodes;
				for(int j=0; j<adjNodes.size(); j++){
					if(nodeList.at(adjNodes.at(j)).distance == -1){
					    nodeList.at(adjNodes.at(j)).distance = cur_distance+1;
					    distanceMap[cur_distance+1].push_back(&nodeList.at(adjNodes.at(j)));
					}
				}
			}
			if(distanceMap[cur_distance+1].size() == 0){
				break;
			}

			cur_distance++;
		}
	}

	void writeDistance(){
		for(int i=0; i<nodeList.size(); i++){
			cout << i+1 << " " << nodeList.at(i).distance << "\n";
		}
	}

	void write(){
		for(int i=0; i<nodeList.size(); i++){
			Node& node = nodeList.at(i);
			cout << node.id << " " << node.adjNodes.size() << " ";

			for(int j=0; j<node.adjNodes.size(); j++){
				cout << node.adjNodes.at(j) << " ";
			}
			cout << "\n";
		}

	}

	void writeMap(){
		map<int, vector<Node*> >::iterator p;
		for(p=distanceMap.begin(); p!=distanceMap.end(); ++p){
			cout << "distance: " << p->first << ", id: ";
			vector<Node*>::iterator p2;
			for(p2=p->second.begin(); p2!=p->second.end(); ++p2){
				cout << (*p2)->id << " ";
			}
			cout << "\n";
		}
	}
};

void writeMatrix(vector<vector<int> > matrix){
	for(int i=0; i<matrix.size(); i++){
		for(int j=0; j<matrix.at(i).size()-1; j++){
			cout << matrix.at(i).at(j) << " ";
		}
		cout << matrix.at(i).at(matrix.at(i).size()-1);
		cout << "\n";
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	Graph g(n);

	for(int i=0; i<m; i++){
		int id_1, id_2;
		cin >> id_1 >> id_2;
		g.nodeList.at(id_1).adjNodes.push_back(id_2);
		g.nodeList.at(id_2).adjNodes.push_back(id_1);
	}

	//g.write();
	int timer = 1;
	g.SearchDepthFirstAll(timer);
	//g.writeSearchResult();

	int q;
	cin >> q;

	for(int i=0; i<q; i++){
		int qid_1, qid_2;
		cin >> qid_1 >> qid_2;
		if(g.nodeList.at(qid_1).group_id == g.nodeList.at(qid_2).group_id){
			cout << "yes\n";
		}else{
			cout << "no\n";
		}
	}

	//g.nodeList.at(0).distance = 0;
	//g.addDistance();
	//g.writeDistance();

	return 0;
}



Measured memory_bytes: 17220