Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	nodes := make([]Node, n)

	for i := 0; i < n; i++ {
		nodes[i].list = make([]int, 0)
	}

	for i := 0; i < m; i++ {
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		nodes[s].list = append(nodes[s].list, t)
		nodes[t].list = append(nodes[t].list, s)
	}

	c := 1
	for i := 0; i < n; i++ {
		if nodes[i].c == 0 {
			traverse(nodes, i, c)
			c++
		}
	}

	q := getNextInt(scanner)

	for i := 0; i < q; i++ {
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		if nodes[s].c == nodes[t].c {
			fmt.Fprintln(writer, "yes")
			continue
		}
		fmt.Fprintln(writer, "no")
	}

	writer.Flush()
}

// Node ...
type Node struct {
	list []int
	c    int
}

func traverse(nodes []Node, r, c int) {
	nodes[r].c = c
	for _, i := range nodes[r].list {
		if nodes[i].c != 0 {
			continue
		}
		traverse(nodes, i, c)
	}
}

C++: /**
 * @brief ?????£???(????§£)??¢?????´?????????????????????
 * @date  2016/03/12~2017/01/03
 * @note  ??¢??£URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_D
 */


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

#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?????????????????????????????§??????. (??°?????????????????????????????°????????????????????¢??????????????¨?????????)
 *         ??°??????????????????????????????????????????????????????????????????????????????????????????????°´???????????§???????????????????????§??????
 *
 * @note   ??????????°?????????¢?????´?????????????????????????????°??????????????????????????????????????????
 *
 *         TOPOLOGICAL-SORT(G)
 *         1 ????????????????????????v.f????¨???????????????????DFS(G)???????????????
 *         2 ?????????????????¢?´¢????????????????????????????????????????????£?????????????????????????????\??????
 *         3 return ???????????£????????????
 *
 * @note   ??±???????????¢?´¢?????(V + E)??????????????????|V|????????????????????????????????£?????????????????????????????\??????????????(1)????????????????????§???
 *         ????????????????????????????????(V + E)????????§????????§??????
 *
 * @param  const graph_t& G ?????????????????°??????
 * @return ??¢??????????????????
 */
array_t tsort(const graph_t& G)
{
    index_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;
}