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

public class A {

static FastReader		sc	= new FastReader();
static PrintWriter	out	= new PrintWriter(System.out);

public static void main(String[] args) throws Exception {
//	try {
	fact=new long[100005];
	fact[0]=1;
	for(int i=1;i<=100004;i++) {
		fact[i]=(fact[i-1]*i)%mod;
	}
	invfact=new long[100005];
	invfact[0]=1;
	for(int i=1;i<100005;i++) {
		invfact[i]=pow(fact[i],mod-2);
	}
int t=sc.nextInt();
while(t-->0) {
	A.go();
}
out.flush();
//	} catch (Exception e) {
//		return;
//	}
}



//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

static void swap(int a[],int i,int j) {
	a[i]=a[i]^a[j];
	a[j]=a[j]^a[i];
	a[i]=a[i]^a[j];
}

static void go() {
int n=sc.nextInt();
int x=sc.nextInt();
int m=sc.nextInt();
long ans=0;
int l=Integer.MAX_VALUE;
int r=Integer.MIN_VALUE;
int q[][]=new int[m][2];
for(int i=0;i<m;i++) {
	int ll=sc.nextInt();
	int rr=sc.nextInt();
q[i][0]=ll;
q[i][1]=rr;
}
int imp[]=new int[m];
for(int i=0;i<m;i++) {
	if(ans==0) {
	if(x>=q[i][0]&&x<=q[i][1]) {
	ans=ans+q[i][1]-q[i][0]+1;
	imp[i]=22;
	}
	continue;
	}
	int minlef=Integer.MAX_VALUE;
	int maxrig=Integer.MIN_VALUE;
	for(int j=0;j<i;j++) {
		if(imp[j]==22) {
			minlef=Math.min(q[j][0],minlef);
			maxrig=Math.max(q[j][1], maxrig);
		}
	}
	if(q[i][0]>=minlef&&q[i][1]<=maxrig) {
		continue;
	}
	if(q[i][0]<=minlef&&q[i][1]>=maxrig) {
		ans=q[i][1]-q[i][0]+1;
		imp[i]=22;
		continue;
	}
	if(q[i][0]==maxrig&& q[i][1]>maxrig) {
		ans=ans+q[i][1]-q[i][0];
		imp[i]=22;
		continue;
	}
	if(q[i][1]==minlef&& q[i][0]<minlef) {
		imp[i]=22;	ans=ans+q[i][1]-q[i][0];continue;
	}
	if(q[i][0]<maxrig&&q[i][1]>maxrig) {
		imp[i]=22;	ans=ans+q[i][1]-maxrig;continue;
	}
	if(q[i][1]>minlef&&q[i][0]<minlef) {
		imp[i]=22;ans=ans+minlef-q[i][0];continue;
	}
//	out.println(ans+""+i);

}

out.println(Math.max(1, ans));
}


static void   print(long a[][]) {
	out.println("--------");
	for(int i=0;i<a.length;i++) {
		for(int j=0;j<a[i].length;j++) {
			out.print(a[i][j]+" ");
		}
		out.println();
	}
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
static long fact[];
static long invfact[];
static long ncr(int n,int k) {
	if(k<0||k>n) {
		return 0;
	}
	long x=fact[n]%mod;
	long y=invfact[k]%mod;
	long yy=invfact[n-k]%mod;
	long ans=(x*y)%mod;
	ans=(ans*yy)%mod;
	return ans;
}
static long gcd(long a, long b) {
	if (b==0) {
		return a;
	}return gcd(b, a%b);
}
static int	prime[]	= new int[200005];
static int	N				= 200005;
static void sieve() {

	for(int i=0;i<N;i++) {
		prime[i]=i;
}
	for (int i = 2; i * i <= N; i++) {
		if (prime[i] == i) {
			prime[i]=i;
			for (int j = i; j < N; j += i) {
				prime[j] =i;
			}}}
}


static int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}return gcd(b, a % b);
}
 static void sort(int[] a) {
	ArrayList<Integer> aa = new ArrayList<>();
	for (Integer i : a) {
		aa.add(i);	}
	Collections.sort(aa);
	for (int i = 0; i < a.length; i++)
		a[i] = aa.get(i);}
static void sort(long[] a) {
	ArrayList<Long> aa = new ArrayList<>();
	for (Long i : a) {
		aa.add(i);}
	Collections.sort(aa);
	for (int i = 0; i < a.length; i++)
		a[i] = aa.get(i);
}

static int mod = (int) 1e9 + 7;

static long pow(long x, long y) {
	long res = 1l;
	while (y != 0) {
		if (y % 2 == 1) {
			res = (x%mod * res%mod)%mod;
			}	y /= 2;
			x = (x%mod * x%mod)%mod;
	}
	return res%mod;
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

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;
	}	}}
class interval implements Comparable<interval>{
	long x,y;
	interval(long x,long y){
		this.x=x;this.y=y;
	}
	@Override
	public int compareTo(interval o) {
		if(o.x==this.x) {
			return Long.compare(o.y,this.y);
		}
		return -Long.compare(o.x, this.x);
	}
}
