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 \le c, d \le 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 \le t \le 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 \le n \le 10^9$; $1 \le m \le 100$; $1 \le x \le 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 \le l_i \le r_i \le 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:  swap $a_k$ and $a_4$;  swap $a_2$ and $a_2$;  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.

Difficulty: interview

Starter code:

Solutions:
t = int(input())
for _ in range(t):
    n, x, m = list(map(int, input().split()))

    left = x
    right = x

    for i in range(m):
        l,r = list(map(int, input().split()))

        if l < left <= r:
            left = l
        if r > right >= l:
            right = r

    print(right - left + 1)


t=int(input())
for _ in range(t):
    n,x,m=map(int,input().split())
    l=x
    r=x
    for i in range(m):
        a,b=map(int,input().split())
        if r>=a and l<=b:
            l=min(l,a)
            r=max(r,b)
    print(r-l+1)

import sys

readline = sys.stdin.readline
read = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, x, m = nm()
    l = r = x
    for _ in range(m):
        p, q = nm()
        if p <= l <= q:
            l = p
        if p <= r <= q:
            r = q
    print(r-l+1)
    return


# solve()

T = ni()
for _ in range(T):
    solve()


tests = int (input())
for test in range (tests):
  n, x, m = map (int, input().split())
  l, r = x, x
  for i in range (m):
    ln, rn = map (int, input().split())
    if ln <= r and rn >= l:
      l = min (l, ln)
      r = max (r, rn)
  print (r - l + 1) 

import sys
input = sys.stdin.readline
for f in range(int(input())):
    n,x,m=map(int,input().split())
    l=x
    r=x
    for i in range(m):
        li,ri=map(int,input().split())
        if li<=r and ri>=l:
            l=min(l,li)
            r=max(r,ri)
    print(r-l+1)

te = int(input())
for t in range(te):
    n, tmp, m = [int(x) for x in input().split()]
    l, r = tmp, tmp
    for i in range(m):
        tl, tr = [int(x) for x in input().split()]
        if max(l, tl) <= min(r, tr):
            l = min(l, tl)
            r = max(r, tr)
    print(r - l + 1)


from collections import defaultdict as dd
import math
import sys
input=sys.stdin.readline
def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))



q=nn()

for _ in range(q):
	n ,x,m=mi()
	minx= x
	maxx= x
	for i in range(m):
		l,r=mi()
		if l<minx and r>=minx:
			minx = l
		if r>maxx and l<=maxx:
			maxx = r
	print(maxx-minx+1)


from queue import Queue
for _ in range(int(input())):
    n, x, m = list(map(int, input().split()))

    ans = [x,x]
    for i in range(m):
        l, r = list(map(int, input().split()))
        if ans[1] < l or ans[0] > r:
            continue
        else:
            ans[0] = min(ans[0], l)
            ans[1] = max(ans[1], r)
    print(ans[1]-ans[0]+1)


T = int(input())
for __ in range(T):
    n, x, m = list(map(int, input().split()))
    i, j = x, x
    for __ in range(m):
        l, r = list(map(int, input().split()))
        if r >= i:
            i = min(i, l)
        if l <= j:
            j = max(j, r)
    print(j - i + 1)


T = int(input())
for _ in range(T):
    N,X,M = list(map(int,input().split()))
    LR = [tuple(map(int,input().split())) for i in range(M)]
    mn = mx = X
    for l,r in LR:
        if l > mx: continue
        if r < mn: continue
        mn = min(mn, l)
        mx = max(mx, r)
    print(mx - mn + 1)


import sys

input=sys.stdin.readline

for _ in range(int(input())):
    n,x,m=list(map(int,input().split()))
    L=x
    R=x
    for i in range(m):
        l,r=list(map(int,input().split()))
        if R<l or r<L:
            continue
        else:
            R=max(R,r)
            L=min(l,L)
    print(R-L+1)


t = int(input())

for i in range(t):
    n,x,m = map(int,input().split())
    leftMost = x
    rightMost = x
    for j in range(m):
        l,r = map(int,input().split())
        if l > rightMost:
            continue
        if r < leftMost:
            continue
        leftMost = min(l,leftMost)
        rightMost = max(r,rightMost)
    print(rightMost - leftMost + 1)

import sys
input = sys.stdin.readline


t = int(input())
for _ in range(t):
    n, x, m = list(map(int, input().split()))
    info = [list(map(int, input().split())) for i in range(m)]
    x -= 1
    ansl, ansr = x, x + 1
    for l, r in info:
        l -= 1
        if max(l, ansl) < min(r, ansr):
            ansl = min(l, ansl)
            ansr = max(r, ansr)
    print(ansr - ansl)


t = int(input())
for _ in range(t):
    n, x, m = list(map(int, input().split()))
    mi, ma = x, x + 1
    for i in range(m):
        l, r = list(map(int, input().split()))
        r += 1
        if l <= mi < r or l < ma <= r:
            mi = min(mi, l)
            ma = max(ma, r)
    print(ma - mi)


import sys
input = sys.stdin.readline

t=int(input())
for tests in range(t):
    n,x,m=list(map(int,input().split()))
    LR=[tuple(map(int,input().split())) for i in range(m)]

    R=x
    L=x

    for l,r in LR:
        if l<=R<=r:
            R=r
        if l<=L<=r:
            L=l

    print(1+R-L)
    
    


#!/usr/bin/env python3
import sys
input = sys.stdin.readline

t = int(input())
for _ in range(t):
    n, x, m = map(int, input().split())
    x -= 1
    minima = x
    maxima = x
    for _ in range(m):
        l, r = map(int, input().split())
        l -= 1; r -= 1
        if r >= minima: 
            minima = min(l, minima)
        if l <= maxima:
            maxima = max(r, maxima)
    print(maxima - minima + 1)

def solve():
    n, x, m = map(int, input().split())
    al, ar = x, x
    for i in range(m):
        l, r = map(int, input().split())
        if max(l, al) <= min(r, ar):
            al = min(al, l)
            ar = max(ar, r)
    print(ar - al + 1)

t = int(input())
for _ in range(t):
    solve()

def read_int():
    return int(input())


def read_ints():
    return list(map(int, input().split(' ')))


t = read_int()
for case_num in range(t):
    n, x, m = read_ints()
    lo = x
    hi = x
    for i in range(m):
        l, r = read_ints()
        if min(r, hi) >= max(lo, l):
            lo = min(lo, l)
            hi = max(hi, r)
    print(hi - lo + 1)


import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
t=N()
def f():
    n,x,m=NM()
    lo=x
    hi=x
    for i in range(m):
        l,r=NM()
        if l<=lo<=r:
            lo=l
        if l<=hi<=r:
            hi=r
    print(hi-lo+1)
for i in range(t):
    f()

t = int(input())
for _ in range(t):
	n, x, m = map(int, input().split())
	a, b = x, x
	for _ in range(m):
		l, r = map(int, input().split())
		if r >= a and b >= l:
			a = min(l, a)
			b = max(r, b)
	print(b-a+1)

for _ in range(int(input())):

    n, x, m = map(int, input().split())
    l = x
    r = x
    for i in range(m):
        a, b = map(int, input().split())
        if a <= r and b >= l:
            r = max(b, r)
            l = min(a, l)
    print(r - l + 1)

for t in range(int(input())):
    n, x, m = list(map(int, input().split()))
    inf = x
    sup = x
    for i in range(m):
        a, b = list(map(int, input().split()))
        if a <= inf <= b:
            sup = max(sup, b)
            inf = min(inf, a)
        if a <= sup <= b:
            inf = min(inf, a)
            sup = max(sup, b)
    print(sup - inf + 1)


def main():
    n, x, m = list(map(int, input().split()))

    tot = [x, x]

    for i in range(m):
        cur = list(map(int, input().split()))
        if (tot[1] >= cur[0] >= tot[0]) or (tot[1] >= cur[1] >= tot[0]) or (cur[1] >= tot[1] and cur[0] <= tot[0]):
            tot[0] = min(cur[0], tot[0])
            tot[1] = max(cur[1], tot[1])
    print(tot[1] - tot[0] + 1)


def __starting_point():
    t = int(input())
    for i in range(t):
        main()

__starting_point()

t = int(input())
for _ in range(t):
    n, x, m = list(map(int, input().split()))
    ansl = x
    ansr = x
    for _ in range(m):
        l, r = list(map(int, input().split()))
        if ansr >= l:
            ansr = max(r, ansr)
        if ansl <= r:
            ansl = min(l, ansl)

    print(ansr-ansl+1)


def intersect(l1,r1,l2,r2):
    if(l1>r2 and r1>r2):
        return 0
    if(r1<l2 and r1<r2):
        return 0
    return 1
t=int(input())
for you in range(t):
    l=input().split()
    n=int(l[0])
    x=int(l[1])
    m=int(l[2])
    ans=0
    done=0
    currleft=-1
    currright=-1
    for i in range(m):
        l=input().split()
        left=int(l[0])
        right=int(l[1])
        if(done==0):
            if(left<=x and x<=right):
                done=1
                currleft=left
                currright=right
        else:
            if(intersect(left,right,currleft,currright)):
                currleft=min(left,currleft)
                currright=max(right,currright)
    print(currright-currleft+1)