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.util.*;
import java.io.*;
import java.math.*;
 
public class Main {

	private static FastReader fr = new FastReader();
	private static Helper helper = new Helper();
	private static StringBuilder result = new StringBuilder();
 
	public static void main(String[] args) {
		Task solver = new Task();
		solver.solve();
	}
 
	static class Task {
	    
	    class Interval{
			public long l;
			public long r;
			public Interval(long l, long r){
				this.l = l;
				this.r = r;
			}
			
			public boolean intersect(Interval i){
				return Math.max(this.l, i.l) <= Math.min(this.r, i.r);
			}
			
			public void union(Interval i){
				this.l = Math.min(l, i.l);
				this.r = Math.max(r, i.r);
			}
			
		}
	    
		public void solve() {
		    int nt = fr.ni();
			while(nt-- > 0){
			    long n = fr.nl(), x = fr.nl(), m = fr.nl();
				Interval ans = new Interval(x, x);
				for(int i=0; i<m; i++){
					long l = fr.nl(), r = fr.nl();
					Interval interval = new Interval(l, r);
					if(ans.intersect(interval)){
						ans.union(interval);
					}
				}
				result.append(ans.r-ans.l + 1).append("\n");
			}
			System.out.println(result);
		}
	}
    
    static class Helper{
		public long[] tiArr(int n, int si){
			long[] arr = new long[n];
			for(int i=si; i<n; i++) arr[i] = fr.nl();
			return arr;
		}
	}
 
	static class FastReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		private static PrintWriter pw;
 
		public FastReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
			pw = new PrintWriter(System.out);
			tokenizer = null;
		}
 
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
 
		public int ni() {
			return Integer.parseInt(next());
		}
 
		public long nl() {
			return Long.parseLong(next());
		}
 
		public String rl() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}
 
		public void print(String str) {
			pw.print(str);
			pw.flush();
		}
	}
}