Problem: After hard work Igor decided to have some rest.

He decided to have a snail. He bought an aquarium with a slippery tree trunk in the center, and put a snail named Julia into the aquarium.

Igor noticed that sometimes Julia wants to climb onto the trunk, but can't do it because the trunk is too slippery. To help the snail Igor put some ropes on the tree, fixing the lower end of the i-th rope on the trunk on the height li above the ground, and the higher end on the height ri above the ground.

For some reason no two ropes share the same position of the higher end, i.e. all ri are distinct. Now Julia can move down at any place of the trunk, and also move up from the lower end of some rope to its higher end. Igor is proud of his work, and sometimes think about possible movements of the snail. Namely, he is interested in the following questions: «Suppose the snail is on the trunk at height x now. What is the highest position on the trunk the snail can get on if it would never be lower than x or higher than y?» Please note that Julia can't move from a rope to the trunk before it reaches the higher end of the rope, and Igor is interested in the highest position on the tree trunk.

Igor is interested in many questions, and not always can answer them. Help him, write a program that answers these questions.

Input

The first line contains single integer n (1 ≤ n ≤ 100000) — the height of the trunk.

The second line contains single integer m (1 ≤ m ≤ 100000) — the number of ropes.

The next m lines contain information about the ropes.

The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the heights on which the lower and the higher ends of the i-th rope are fixed, respectively. It is guaranteed that all ri are distinct.

The next line contains single integer q (1 ≤ q ≤ 100000) — the number of questions.

The next q lines contain information about the questions.

Each of these lines contain two integers x and y (1 ≤ x ≤ y ≤ n), where x is the height where Julia starts (and the height Julia can't get lower than), and y is the height Julia can't get higher than.

Output

For each question print the maximum reachable for Julia height.

Examples

Input

8
4
1 2
3 4
2 5
6 7
5
1 2
1 4
1 6
2 7
6 8


Output

2
2
5
5
7


Input

10
10
3 7
1 4
1 6
5 5
1 1
3 9
7 8
1 2
3 3
7 10
10
2 4
1 7
3 4
3 5
2 8
2 5
5 5
3 5
7 7
3 10


Output

2
7
3
3
2
2
5
3
7
10

Note

The picture of the first sample is on the left, the picture of the second sample is on the right. Ropes' colors are just for clarity, they don't mean anything.

<image>

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class F {
    private FastScanner in;
    private PrintWriter out;

    class Segment implements Comparable<Segment> {
        int l, r;

        public Segment(int l, int r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public int compareTo(Segment o) {
            return Integer.compare(l, o.l);
        }

        @Override
        public String toString() {
            return "Segment{" +
                    "l=" + l +
                    ", r=" + r +
                    '}';
        }
    }

    class Q implements Comparable<Q> {
        int id;
        int x, y;

        public Q(int id, int x, int y) {
            this.id = id;
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Q o) {
            return Integer.compare(x, o.x);
        }
    }

    void addSegment(Segment s) {
        allSegments.add(s);
        if (allSegments.size() == 800) {
            int from = allSegments.get(allSegments.size() - 1).l;
            TreeSet<Integer> right = new TreeSet<>();
            for (int i = allSegments.size() - 1; i >= 0; i--) {
                right.add(allSegments.get(i).r);
                int next = i == 0 ? up[0].length : allSegments.get(i - 1).l;
                int min = Integer.MAX_VALUE;

                for (int pos = allSegments.get(i).l; pos < next; pos++) {
                    if (min == Integer.MAX_VALUE || min <= pos) {
                        min = Integer.MAX_VALUE;
                        while (right.size() > 0) {
                            int v = right.first();
                            if (v > pos) {
                                min = v;
                                break;
                            } else {
                                right.remove(v);
                            }
                        }
                    }
                    up[0][pos] = Math.min(up[0][pos], min);
                }
            }
            allSegments.clear();
            for (int i = 1; i < LOG; i++) {
                for (int j = from; j < up[i].length; j++) {
                    up[i][j] = up[i - 1][j] == Integer.MAX_VALUE ? Integer.MAX_VALUE : up[i - 1][up[i - 1][j]];
                }
            }
        }
    }

    final int LOG = 10;
    int[][] up;

    ArrayList<Segment> allSegments = new ArrayList<>();

    final int MAX = 100000;

    private void solve123() {
        long START = System.currentTimeMillis();
        int n = MAX;
        int m = MAX;
        Segment[] segs = new Segment[m];
        Random rnd = new Random(123);
        for (int i = 0; i < m; i++) {
            int fr = rnd.nextInt(MAX);
            int to = rnd.nextInt(MAX);
            if (fr > to) {
                int tmp = fr;
                fr = to;
                to = tmp;
            }
            segs[i] = new Segment(fr, to);
        }
        Arrays.sort(segs);
        int cnt = MAX;
        Q[] q = new Q[cnt];
        for (int i = 0; i < cnt; i++) {
            int fr = rnd.nextInt(MAX);
            int to = rnd.nextInt(MAX);
            if (fr > to) {
                int tmp = fr;
                fr = to;
                to = tmp;
            }
            q[i] = new Q(i, fr, to);
        }
        Arrays.sort(q);
        int[] ans = new int[q.length];
        int iter = segs.length - 1;
        up = new int[LOG][n];
        for (int j = 0; j < LOG; j++) {
            for (int i = 0; i < n; i++) {
                up[j][i] = Integer.MAX_VALUE;
            }
        }
        for (int qIt = q.length - 1; qIt >= 0; qIt--) {
//            System.err.println("!" + qIt);
            while (iter != -1 && segs[iter].l >= q[qIt].x) {
                addSegment(segs[iter]);
                iter--;
            }
            int pos = q[qIt].x;
            int max = q[qIt].y;
            int it = allSegments.size() - 1;
            while (true) {
                int wasPos = pos;
                for (int i = LOG - 1; i >= 0; i--) {
                    if (up[i][pos] <= max) {
                        pos = up[i][pos];
                    }
                }
                while (it != -1) {
                    if (allSegments.get(it).l > pos) {
                        break;
                    }
                    if (allSegments.get(it).r <= pos || allSegments.get(it).r > max) {
                        it--;
                        continue;
                    }
                    pos = Math.max(pos, allSegments.get(it).r);
                    it--;
                }
                if (pos == wasPos) {
                    break;
                }
            }
            ans[q[qIt].id] = pos;
        }
        for (int z : ans) {
//            out.println(z + 1);
        }
        System.err.println(System.currentTimeMillis() - START);
    }

    private void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        Segment[] segs = new Segment[m];
        for (int i = 0; i < m; i++) {
            segs[i] = new Segment(in.nextInt() - 1, in.nextInt() - 1);
        }
        Arrays.sort(segs);
        int cnt = in.nextInt();
        Q[] q = new Q[cnt];
        for (int i = 0; i < cnt; i++) {
            q[i] = new Q(i, in.nextInt() - 1, in.nextInt() - 1);
        }
        Arrays.sort(q);
        int[] ans = new int[q.length];
        int iter = segs.length - 1;
        up = new int[LOG][n];
        for (int j = 0; j < LOG; j++) {
            for (int i = 0; i < n; i++) {
                up[j][i] = Integer.MAX_VALUE;
            }
        }
        for (int qIt = q.length - 1; qIt >= 0; qIt--) {
            while (iter != -1 && segs[iter].l >= q[qIt].x) {
                addSegment(segs[iter]);
                iter--;
            }
            int pos = q[qIt].x;
            int max = q[qIt].y;
            int it = allSegments.size() - 1;
            while (true) {
                int wasPos = pos;
                for (int i = LOG - 1; i >= 0; i--) {
                    if (up[i][pos] <= max) {
                        pos = up[i][pos];
                    }
                }
                while (it != -1) {
                    if (allSegments.get(it).l > pos) {
                        break;
                    }
                    if (allSegments.get(it).r <= pos || allSegments.get(it).r > max) {
                        it--;
                        continue;
                    }
                    pos = Math.max(pos, allSegments.get(it).r);
                    it--;
                }
                if (pos == wasPos) {
                    break;
                }
            }
            ans[q[qIt].id] = pos;
        }
        for (int z : ans) {
            out.println(z + 1);
        }
    }

    private void run() {
        try {
            in = new FastScanner(new File("F.in"));
            out = new PrintWriter(new File("F.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new F().runIO();
    }
}