Go: package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

// Node 頂点
type Node struct {
	gid  int   // グループID
	edge []int // 隣接辺
}

// NoID グループIDなし
const NoID = -1

// NewNode 頂点の生成
func NewNode() *Node {
	return &Node{gid: NoID, edge: []int{}}
}

func parseNode(nodes []*Node, gid int, queue []int) {
	if len(queue) == 0 {
		return
	}
	var nextQ []int
	for _, id := range queue {
		node := nodes[id]
		if node.gid == NoID {
			node.gid = gid
			for _, edge := range node.edge {
				nextQ = append(nextQ, edge)
			}
		}
	}
	parseNode(nodes, gid, nextQ)
	return
}
func digNode(nodes []*Node, id, gid int) {
	node := nodes[id]
	if node.gid != NoID {
		// 探索済み
		return
	}
	node.gid = gid
	for _, edge := range node.edge {
		digNode(nodes, edge, gid)
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n, m := eGetInt2(scanner)

	nodes := make([]*Node, n)
	for i := 0; i < n; i++ {
		nodes[i] = NewNode()
	}

	for i := 0; i < m; i++ {
		a, b := eGetInt2(scanner)
		nodes[a].edge = append(nodes[a].edge, b)
		nodes[b].edge = append(nodes[b].edge, a)
	}

	for i := 0; i < n; i++ {
		// 幅優先探索
		// gid := i
		// queue := []int{i}
		// parseNode(nodes, gid, queue)

		// 深さ優先探索
		digNode(nodes, i, i)
	}

	q := eGetInt(scanner)
	for i := 0; i < q; i++ {
		a, b := eGetInt2(scanner)
		if nodes[a].gid == nodes[b].gid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

func eGetInt(scanner *bufio.Scanner) int {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0]
}
func eGetInt2(scanner *bufio.Scanner) (int, int) {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0], t[1]
}

func eGetline(p *bufio.Scanner) string {
	if !p.Scan() {
		if err := p.Err(); err != nil {
			log.Fatal(err.Error())
		}
		return ""
	}
	return p.Text()
}

func eAtoi(s []string) []int {
	ints := make([]int, len(s))
	var err error
	for i, e := range s {
		ints[i], err = strconv.Atoi(e)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
	return ints
}

C++: /**
 * @brief ?????£???(????§£)??¢?????´?????????????????????
 * @date  2016/03/12
 */


//****************************************
// ???????????????????????????????????????????????????
//****************************************

#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <vector>
#include <iostream>



//****************************************
// ???????????§????????¢?????????????????????
//****************************************

#define GRAPH_BEGIN namespace graph {
#define GRAPH_END   }



//****************************************
// ????????????????§????
//****************************************

GRAPH_BEGIN



//****************************************
// ?§????????????????
//****************************************

using weight_t   = std::int32_t;  /**< ???(u, v)????????????w?????¨?????? */
using index_t    = std::int32_t;  /**< ??????v??????????????¨??????       */
using capacity_t = weight_t;      /**< ???(u, v)??????????????¨??????    */



namespace limits {
    enum {  // namespace graph????????£???scoped??§????????????????????????????????????enum(strongly-typed enum)??§?????????
    inf = std::numeric_limits<weight_t>::max() / 3,  /**< @brief ???????????¨???????????´???????????¨????????????     */
    nil = std::numeric_limits<index_t>::min() / 3,   /**< @brief ?????????????????¨???????????´???????????¨???????????? */
};
}



/**
 * @brief  ????????????????§???????(scoped enum)
 * @detail (u, v) ??? E??§??????u??????????????°??????v?????°????????§??????
 *         ?????????????????????????????£??\????????¨?????????????????????????????§??????
 *         ??°???????????????????????£??\???????????¨???????????????????????????????????¢??????????????¨???????????????????¢?????????????
 */
enum struct vcolor : std::int32_t {
    white,  /**< ??????????????? */
    black,  /**< ??¢???????????? */
    gray,   /**< ??¢???????????? */
};

/**
 * @brief ??°????????¨?????????(??????) 
 */
struct vertex {
    union {
        weight_t d;       /**< ?§????s??????????????¢  */
        weight_t key;     /**< Prim?????¢?????´???????????????????????¨????±?????????????????????¨????????¶?????? */
    };
    index_t pi;           /**< ????????????(?????????) */
    union {
        vcolor color;     /**< ????????????        */
        bool  visited;    /**< ????????????????     */
    };
    // weight_t f;           /**< ??????????????°(DFS?????????????????????????????????????????¨??????????????????)     */
    vertex() : d(0), pi(0), color(vcolor::white)/*, f(0)*/ {}
};

/**
 * @brief ??°????????¨??¨??????(???)
 * @note  G = (V, E)???????????¢??°w???????????????????????°????????¨????????¨???
 *        ???(u, v) ??? E????????????w(u, v)??¨??¨?????????
 */
struct edge {
    index_t  src;   /**< ???????§????u */
    index_t  dst;   /**< ????????????v */
    union {
        weight_t w;     /**< ???(u, v)????????????(?????????) */
        capacity_t c;   /**< ???(u, v)????????? */
    };
    edge() = default;
    edge(index_t src, index_t dst) : src(src), dst(dst), w(1) {}
    edge(index_t src, index_t dst, weight_t w) : src(src), dst(dst), w(w) {}

    bool operator < (const edge& e) const { return w < e.w; }
    bool operator > (const edge& e) const { return w > e.w; }
};



using edges_t    = std::vector<edge>;      /**< ??°??????G=(V, E)????????????E   */
using vertices_t = std::vector<vertex>;    /**< ??°??????G=(V, E)???????????????V */
using array_t    = std::vector<weight_t>;  /**< ??????w?????????  */
using indices_t  = std::vector<index_t>;   /**< ????????????????????? */
using matrix_t   = std::vector<array_t>;   /**< ??°??????G?????£??\????????¨???(???????????¨????????¨???) */
using graph_t    = std::vector<edges_t>;   /**< ??°??????G?????£??\???????????¨???(???????????????????????¨??????) */



//****************************************
// ??¢??°?????????
//****************************************

/**
 * @brief  ??????????????????????????????????????????
 *
 * @note   ?????????????????°??????G = (V, E)??????????????????????????????(topological sort)??????????????????????????¢????????§???
 *         G??????(u, v)?????????????????°??????????????¢????????§u???v?????????????????????????????§??????. (??°?????????????????????????????°????????????????????¢??????????????¨?????????)
 *         ??°??????????????????????????????????????????????????????????????????????????????????????????????°´???????????§???????????????????????§??????
 * @param  const graph& G ?????????????????°??????
 * @return ??¢??????????????????
 */
array_t tsort(const graph_t& G)
{
    std::int32_t n = G.size();
    std::vector<vcolor> color(n, vcolor::white);
    array_t lst(n);

    // ?????????????¨???????
    std::function<bool(index_t)> dfs_visit = [&](index_t u) {
        color[u] = vcolor::gray;    // u?????°???????????????
        for (auto&& e : G[u]) {      // v??¨??£??\???????????????w????????????
            index_t w = e.dst;
            if (color[w] == vcolor::white
             && !dfs_visit(w)) { return false; }  // w?????????????????°??????w????????????
        }
        color[u] = vcolor::black;   // u?????????????????????
        lst.push_back(u);           // ????????????????°?????????\??????
        return true;
    };


    // ?????????v???????????????v.f????¨???????????????????DFS(G)???????????????
    for (index_t v = 0; v < n; v++) {
        if (color[v] == vcolor::white && !dfs_visit(v)) { return {}; };
    }
    reverse(lst.begin(), lst.end());  // ??????????????????????????????????????????????????§reverse?????????
    return lst;     // ???????????????????????????
}




/**
 * @brief  ?????£?????????(????§£)??¢?????´?????????
 *
 * @note   ??°??????????????£????????????????§£??????????????????????????£??????????????§??¢?????´????????????????????????
 *         ?????????????§£?????????????????£????§??????????????????£??????????????????????????????????§£?????????
 *
 * @note   ??°??????G = (V, E)????????£?????????????±?????????¢?????´????????????G?????¢????????¨??????
 *         G?????¢????????°??????G^T = (V, E^T), E^T = { (u, v) : (v, u) ??? E }??§??????
 *         ???????????????E^T???G??????????????????????????????????????§??????. G?????£??\?????????????????????????????¨???
 *         G^T?????(V + E)????????§????????§??????. ????????±????????¨??????G??¨G^T????????£?????????????????£??????????????????
 *         G?????§u??¨v??????????????°???????????§???????????¨??¨???G^T?????§???????????????????????°???????????§???????????¨??¨???????????§??????
 *
 * @note   ??\???????????¢??????(?????????????????(V + E)??????)??¢?????´?????????????????±???????????¢?´¢???2???????????????G?????§???
 *         ?????????G^T?????§?????????????????¨????????£???????????°??????G = (V, E)????????£?????????????±???????
 *
 *         STRONGLY-CONNECTED-COMPONENTS(G)
 *         1 DFS(G)???????????????????????????u????????????????????????u.f????¨??????????
 *         2 G^T????¨??????????
 *         3 DFS(G^T)?????????????????????DFS?????????????????§???(?¬¬1?????§?¨??????????)u.f???????????§???????????¢?´¢??????
 *         4 ?¬¬3?????§??????????????±??????????£?????????¨????????????????????????????????¢??????????????£???????????¨??????????????????
 *
 * @param  const graph_t& G ??°??????G
 * @return components[v] ??????v?????????????????£????????????????????¨?????????????????????
 */
indices_t scc(const graph_t& G)
{
    index_t n = G.size(); vertices_t vs(n);
    indices_t components(n, -1);
    std::vector<vcolor> color(n, vcolor::white);
    graph_t GT(n);

    // ?????°???????????????????¨???????
    std::function<void(index_t, index_t)> dfs_visit = [&](index_t u, index_t k) {
        color[u] = vcolor::gray;
        components[u] = k;
        for (auto&& e : GT[u]) {
            index_t w = e.dst;
            if (color[w] == vcolor::white) {
                dfs_visit(w, k);
            }
        }
        color[u] = vcolor::black;
    };


    // DFS(G)???????????????????????????u????????????????????????u.f????¨??????????
    array_t tlst = tsort(G);

    // G^T????¨??????????
    for (auto&& es : G) {
        for (auto&& e : es) {
            GT[e.dst].emplace_back(e.dst, e.src);
        }
    }

    // DFS(G^T)???????????????
    index_t k = 0;
    for (auto&& u : tlst) { // ????????°??????????????????????????????????????????????????????????????§?¨??????????
        if (color[u] == vcolor::white) {
            dfs_visit(u, k++);
        }
    }

    // ?????¢??????????????£??????????????????
    return components;
}



//****************************************
// ?????????????????????
//****************************************

GRAPH_END



//****************************************
// ??¨?????????????????????
//****************************************

int main()
{
    using namespace std;
    using namespace graph;
    
    graph_t G;
    int s, t, m, n, q;
    cin >> n >> m;
    G.resize(n);
    for (index_t i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].emplace_back(s, t);
        G[t].emplace_back(t, s);
    }

    auto _scc = scc(G);

    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> s >> t;
        cout << ((_scc[s] == _scc[t]) ? "yes" : "no") << endl;
    }

    return 0;
}