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.math.*;
import java.util.*;

public class test {

	public static void main(String[] args) {
		int t = fs.nextInt();
//		int t = 1;
		for (int i = 0; i < t; i++) {
			int n = fs.nextInt();
			int x = fs.nextInt();
			int m = fs.nextInt();
			int index = x;
			int oi = x;
			int ni = x;
			for (int s = 0; s < m; s++) {
				int start = fs.nextInt();
				int end = fs.nextInt();
				if (start >= oi && end <= ni) {
					continue;
				}
				if ((start >= oi && start <= ni) && end >= ni) {
					ni = end;
				}
				if ((end >= oi && end <= ni) && oi >= start) {
					oi = start;
				}
				if (start <= oi && end >= ni) {
					oi = start;
					ni = end;
				}
			}
			System.out.println(ni - oi + 1);

		}
	}
	/*
	 * array list
	 * 
	 * ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers
	 * 
	 * BigInteger a=new BigInteger(); BigInteger b=new BigInteger();
	 * 
	 * hash map
	 * 
	 * HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int
	 * i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) {
	 * hm.put(ar[i],1); } else { hm.put(ar[i],++c); } }
	 * 
	 * while loop
	 * 
	 * int t=sc.nextInt(); while(t>0) { t--; }
	 * 
	 * array input
	 * 
	 * int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length;
	 * i++) { ar[i] = sc.nextInt(); }
	 */

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static class Pair {
		int first, second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}

	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

	}

	private static final Scanner sc = new Scanner(System.in);
	private static final FastReader fs = new FastReader();
	private static final OutputWriter op = new OutputWriter(System.out);

	static int[] getintarray(int n) {
		int ar[] = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextInt();
		}
		return ar;
	}

	static long[] getlongarray(int n) {
		long ar[] = new long[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextLong();
		}
		return ar;
	}

	static int[][] get2darray(int n, int m) {
		int ar[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ar[i][j] = fs.nextInt();
			}
		}
		return ar;
	}

	static Pair[] getpairarray(int n) {
		Pair ar[] = new Pair[n];
		for (int i = 0; i < n; i++) {
			ar[i] = new Pair(fs.nextInt(), fs.nextInt());
		}
		return ar;
	}

	static void printarray(int ar[]) {
		System.out.println(Arrays.toString(ar));
	}

	static int fact(int n) {
		int fact = 1;
		for (int i = 2; i <= n; i++) {
			fact *= i;
		}
		return fact;
	}

//	static int getans(int[] a, int[] b) {
//		int a1 = a[0];
//		int a2 = b[0];
//		int b1 = a[1];
//		int b2 = b[1];
//		int c1 = a[2];
//		int c2 = b[2];
//
//		if (((a1 == a2) && (b1 == b2) && (c1 == c2)))
//			return 0;
//		else if ((a2 - a1) == (b2 - b1) && (b2 - b1) == (c2 - c1))
//			return 1;
//		else if ((a2 / a1 == b2 / b1) && (b2 / b1 == c2 / c1) && (a2 / a1 == c2 / c1)
//				&& (a2 % a1 == 0 && b2 % b1 == 0 && c2 % c1 == 0))
//			return 1;
//		else if (((a1 == a2) && (b1 == b2)) || ((a1 == a2) && (c1 == c2)) || ((c1 == c2) && (b1 == b2))) {
//			return 1;
//		} else if (a1 == a2) {
//			if ((b2 - b1) == (c2 - c1) || ((b2 / b1 == c2 / c1) && (b2 % b1 == 0 && c2 % c1 == 0)))
//				return 1;
//		} else if (b1 == b2) {
//			if ((a2 - a1) == (c2 - c1) || ((a2 / a1 == c2 / c1) && (a2 % a1 == 0 && c2 % c1 == 0)))
//				return 1;
//		} else if (c1 == c2) {
//			if ((b2 - b1) == (a2 - a1) || ((b2 / b1 == a2 / a1) && (b2 % b1 == 0 && a2 % a1 == 0)))
//				return 1;
//		} else if ((((a2 - a1) != (b2 - b1) && (b2 - b1) != (c2 - c1) && (a2 - a1) != (c2 - c1))
//				&& ((a2 / a1 != b2 / b1) && (b2 / b1 != c2 / c1) && (a2 / a1 != c2 / c1)))) {
//			return 3;
//		} else if ((((a2 - a1) != (b2 - b1) && (b2 - b1) != (c2 - c1) && (a2 - a1) != (c2 - c1)))) {
//			if ((a2 / a1 == b2 / b1 && a2 % a1 != 0 && b2 % b1 != 0)
//					|| (a2 / a1 == c2 / c1 && a2 % a1 != 0 && c2 % c1 != 0)
//					|| (c2 / c1 == b2 / b1 && c2 % c1 != 0 && b2 % b1 != 0))
//				return 3;
//
//		}
//		return 2;
//
//	}

	// function to find largest prime factor

}/*
	 * 1 5 -2 -3 -1 -4 -6till here
	 */

//		while (t > 0) {
//			int a[] = getintarray(3);
//			int b[] = getintarray(3);
//			int ans = getans(a, b);
//			System.out.println(ans);
//		}