Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < M; i++ {
		s, t := sc.nextInt(), sc.nextInt()
		G[s] = append(G[s], t)
		G[t] = append(G[t], s)
	}
	group := make([]int, N)
	for i := 0; i < N; i++ {
		group[i] = -1
	}
	var dfs func(cur int)
	dfs = func(cur int) {
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if group[next] == -1 {
				group[next] = group[cur]
				dfs(next)
			}
		}
	}
	num := 0
	for i := 0; i < N; i++ {
		if group[i] == -1 {
			group[i] = num
			dfs(i)
			num++
		}
	}

	Q := sc.nextInt()
	for i := 0; i < Q; i++ {
		s, t := sc.nextInt(), sc.nextInt()
		if group[s] == group[t] {
			fmt.Fprintln(wtr, "yes")
		} else {
			fmt.Fprintln(wtr, "no")
		}
	}
	wtr.Flush()
}

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;
}