using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CompProgLib;

namespace ALDS1_11_D
{
    public class Program

    {
        public static void Main(string[] args)
        {
            Graph gr = new Graph();
            int[] line = ReadIntAr();
            for (int i = 0 ; i < line[0] ; i++)
            {
                gr.SetGraph(i, null);
            }

            for (int i = 0 ; i < line[1] ; i++)
            {
                int[] friends = ReadIntAr();
                gr.AddVertex(friends[0], friends[1]);
                gr.AddVertex(friends[1], friends[0]);
            }

            gr.SetGroup();

            int n = ReadInt();
            for (int i = 0 ; i < n ; i++)
            {
                int[] Connections = ReadIntAr();
                if (gr.Adj[Connections[0]].Group != gr.Adj[Connections[1]].Group)
                {
                    Console.WriteLine("no");
                }
                else
                {
                    Console.WriteLine("yes");
                }
               
            }

        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}

namespace CompProgLib
{
    public class Graph
    {
        public class Node
        {
            public List<int> Vertex { get; internal set; }
            public int D { get; internal set; }
            public int F { get; internal set; }
            public bool IsVisited { get; internal set; }
            public int Group { get; internal set; }
            public int Depth { get; internal set; }

            public Node(List<int> v)
            {
                Vertex = v;
                Depth = -1;
                Group = -1;
            }
        }

        public Dictionary<int, Node> Adj { get; set; }

        public Graph()
        {
            Adj = new Dictionary<int, Node>();
        }

        public void AddVertex(int index, int v)
        {
            if (!Adj[index].Vertex.Contains(v))
            {
                Adj[index].Vertex.Add(v);
            }
        }

        /// <summary>
        /// 隣接行列の指定したインデックスに値をセットする
        /// </summary>
        /// <param name="index">頂点u</param>
        /// <param name="item">頂点uに接続する頂点</param>
        public void SetGraph(int index, int[] item)
        {
            if (item == null)
            {
                Adj.Add(index, new Node(new List<int>()));
            }
            else
            {
                Adj.Add(index, new Node(item.ToList()));
            }
        }

        /// <summary>
        /// 行列を0で初期化する
        /// </summary>
        public void Clear() { Adj.Clear(); }

        /// <summary>
        /// 深さ優先探索
        /// </summary>
        private int Time = 0;
        public void DFS(int v)
        {
            Adj[v].D = ++Time;
            Adj[v].IsVisited = true;
            foreach (int vertex in Adj[v].Vertex)
            {
                if (!Adj[vertex].IsVisited) DFS(vertex);
            }
            Adj[v].F = ++Time;
        }

        /// <summary>
        /// 訪問済フラグをクリアする
        /// </summary>
        private void InitVisitFlag()
        {
            foreach (KeyValuePair<int, Node> item in Adj) item.Value.IsVisited = false;
        }

        /// <summary>
        /// 幅優先探索
        /// </summary>
        /// <param name="v"></param>
        public void BFS(int v)
        {
            Queue<Node> que = new Queue<Node>();

            Adj[v].Depth = 0;
            Adj[v].IsVisited = true;
            que.Enqueue(Adj[v]);

            while (que.Count() != 0)
            {
                Node node = que.Dequeue();
                foreach (int vertex in node.Vertex)
                {
                    if (!Adj[vertex].IsVisited)
                    {
                        Adj[vertex].IsVisited = true;
                        Adj[vertex].Depth = node.Depth + 1;
                        que.Enqueue(Adj[vertex]);

                    }
                }
            }

        }

        /// <summary>
        /// 頂点間の最短距離を返す
        /// </summary>
        /// <param name="start">始点</param>
        /// <param name="end">終点</param>
        /// <returns>
        /// 始点と終点の距離
        /// 始点と終点が連結されていない場合は-1を返す
        /// </returns>
        public int GetDistance(int start, int end)
        {
            InitVisitFlag();
            Queue<Node> que = new Queue<Node>();

            Adj[start].IsVisited = true;
            Adj[start].Depth = 0;

            if (start == end) return Adj[start].Depth;
            que.Enqueue(Adj[start]);

            while (que.Count() != 0)
            {
                Node node = que.Dequeue();
                foreach (int vertex in node.Vertex)
                {
                    if (!Adj[vertex].IsVisited)
                    {
                        Adj[vertex].IsVisited = true;
                        Adj[vertex].Depth = node.Depth + 1;

                        if (vertex == end) return Adj[vertex].Depth;
                        que.Enqueue(Adj[vertex]);
                    }
                }
            }
            return -1;
        }

        public void SetGroup()
        {
            int group = 0;
            foreach (KeyValuePair<int, Node> item in Adj) 
            {
                if(item.Value.Group < 0)
                {
                    _SetGroup(item.Key,group);
                }
                group++;
            }
        }

        private void _SetGroup(int key, int group)
        {

            Queue<Node> que = new Queue<Node>();

            Adj[key].Group = group;
            que.Enqueue(Adj[key]);

            while (que.Count() != 0)
            {
                Node node = que.Dequeue();
                foreach (int vertex in node.Vertex)
                {
                    if (Adj[vertex].Group <0)
                    {
                        Adj[vertex].Group = group;
                        que.Enqueue(Adj[vertex]);
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 39960