You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.

You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.

Calculate the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Then the description of t testcases follow.

The first line of each test case contains three integers n, x and m (1 ≤ n ≤ 10^9; 1 ≤ m ≤ 100; 1 ≤ x ≤ n).

Each of next m lines contains the descriptions of the operations; the i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n).

Output

For each test case print one integer — the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Example

Input


3
6 4 3
1 6
2 3
5 5
4 1 2
2 4
1 2
3 3 2
2 3
1 2


Output


6
2
3

Note

In the first test case, it is possible to achieve a_k = 1 for every k. To do so, you may use the following operations:

  1. swap a_k and a_4; 
  2. swap a_2 and a_2; 
  3. swap a_5 and a_5. 



In the second test case, only k = 1 and k = 2 are possible answers. To achieve a_1 = 1, you have to swap a_1 and a_1 during the second operation. To achieve a_2 = 1, you have to swap a_1 and a_2 during the second operation.
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class B {
    static final int MOD = 1000000007; // 1e9 + 7
    static final boolean AUTO_FLUSH = false; // slow if true
    // int = num(); // long = ll();
    // string = next(); // a string line = line();
    // ---------------------------------- \

    void main() {
        int t = num();
        while (t-- > 0) {
            int n = num(), x = num(), m = num();
            int l = x, r = x;
            while (m-- > 0) {
                int a = num(), b = num();
                if (a <= l && l <= b || a <= r && r <= b) {
                    l = Math.min(l, a);
                    r = Math.max(r, b);
                }
            }
            outln(r - l + 1);
        }
    }

    // ---------------------------------- \
    // #region
    public static void main(String[] args) {
        startTime();
        new B().main();
        boolean endsWithEnter = TO_BE_PRINTED.length() == 0 || TO_BE_PRINTED.charAt(TO_BE_PRINTED.length() - 1) == '\n';
        flush();
        if (!endsWithEnter)
            log('\n');
        logTime();
        logMem();
    }

    static class PairInt extends Pair<Integer, Integer> {
        public PairInt(int a, int b) {
            super(a, b);
        }
    }

    static class Pair<T extends Comparable<T>, T2 extends Comparable<T2>> implements Comparable<Pair<T, T2>> {
        public T a;
        public T2 b;

        public Pair(T a, T2 b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair<T, T2> p) {
            int comp = a.compareTo(p.a);
            if (comp == 0)
                return b.compareTo(p.b);
            return comp;
        }

        @Override
        public String toString() {
            return "[" + a + "," + b + "]";
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((a == null) ? 0 : a.hashCode());
            result = prime * result + ((b == null) ? 0 : b.hashCode());
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            @SuppressWarnings("unchecked")
            Pair<T, T2> other = (Pair<T, T2>) obj;
            if (a == null) {
                if (other.a != null)
                    return false;
            } else if (!a.equals(other.a))
                return false;
            if (b == null) {
                if (other.b != null)
                    return false;
            } else if (!b.equals(other.b))
                return false;
            return true;
        }
    }

    static Random RAND = new Random();

    static int random(int from, int to) {
        return RAND.nextInt(to - from + 1) + from;
    }

    static void logTime() {
        log("Time: " + getTime() + "ms");
    }

    static void logMem() {
        log("Memory (End): " + (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024
                + " KB");
    }

    static long ll() {
        return Long.parseLong(next());
    }

    static long[] lls(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; ++i) {
            res[i] = ll();
        }
        return res;
    }

    static int num() {
        return Integer.parseInt(next());
    }

    static int[] nums(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = num();
        }
        return res;
    }

    static void generateInputMode() throws Exception {
        System.setOut(new PrintStream(new FileOutputStream("~/kode/input.txt")));
    }

    static String line() {
        if (!tokenize())
            return null;
        INPUT_STREAM.setLength(0);
        if (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(STRING_TOKENIZER.nextToken());
        while (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(' ').append(STRING_TOKENIZER.nextToken());
        return INPUT_STREAM.length() == 0 ? null : INPUT_STREAM.toString();
    }

    static void startTime() {
        TIME_COMPLEXITY = System.currentTimeMillis();
    }

    static long getTime() {
        return System.currentTimeMillis() - TIME_COMPLEXITY;
    }

    static void flush() {
        System.out.print(TO_BE_PRINTED.toString());
        TO_BE_PRINTED.setLength(0);
    }

    static void out(Object o) {
        TO_BE_PRINTED.append(o);
        if (AUTO_FLUSH)
            flush();
    }

    static void _log(String s) {
        System.err.print(s);
    }

    static void _logln(String s) {
        System.err.println(s);
    }

    static void _logln() {
        System.err.println();
    }

    static void outln(Object o) {
        out(o);
        outln();
    }

    static void outln() {
        out("\n");
    }

    static void logArr(Object val) {
        Class<?> valKlass = val.getClass();
        Object[] outputArray = null;
        for (Class<?> arrKlass : new Class<?>[] { int[].class, float[].class, double[].class, boolean[].class,
                byte[].class, short[].class, long[].class, char[].class }) {
            if (valKlass.isAssignableFrom(arrKlass)) {
                int arrlength = Array.getLength(val);
                outputArray = new Object[arrlength];
                for (int i = 0; i < arrlength; ++i)
                    outputArray[i] = Array.get(val, i);
                break;
            }
        }
        if (outputArray == null)
            outputArray = (Object[]) val;
        logArr0(outputArray);
    }

    static void logArr0(Object[] objs) {
        if (objs.length == 0) {
            _log("* \n");
            return;
        }
        _log("* " + objs[0]);
        for (int i = 1; i < objs.length; i++)
            _log(objs[i].toString().equals("\n") ? "\n>" : (" " + objs[i]));
        _logln();
    }

    static void log(Object... objs) {
        logArr0(objs);
    }

    static String next() {
        return tokenize() ? STRING_TOKENIZER.nextToken() : null;
    }

    static boolean tokenize() {
        if (STRING_TOKENIZER == null || !STRING_TOKENIZER.hasMoreTokens()) {
            try {
                STRING_TOKENIZER = new StringTokenizer(STREAM_READER.readLine());
            } catch (Exception _e) {
                return false;
            }
        }
        return true;
    }

    static long TIME_COMPLEXITY;
    static BufferedReader STREAM_READER = new BufferedReader(new InputStreamReader(System.in), 32768);
    static StringTokenizer STRING_TOKENIZER;
    static StringBuilder INPUT_STREAM = new StringBuilder(), TO_BE_PRINTED = new StringBuilder();
    // #endregion
}