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: EASY
Tags: Amortized analysis

Mathematics
Skill types: Amortized analysis

Starter code:

Solutions:
t = int(input())
for q in range(t):
	s = set()
	(n, x, m) = input().split()
	(n, x, m) = (int(n), int(x), int(m))
	(l1, r1) = (x, x)
	for w in range(m):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		if x >= l and x <= r or (l1 <= l and r1 >= l) or (l1 <= r and r1 >= r):
			if l < l1:
				l1 = l
			if r > r1:
				r1 = r
	print(r1 - l1 + 1)


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


def solve():
	(n, x, m) = map(int, input().split())
	r = []
	for i in range(m):
		r.append(list(map(int, input().split())))
	end = x
	start = x
	for i in range(0, m):
		if r[i][0] < start and r[i][1] < start:
			continue
		if end < r[i][0] and end < r[i][1]:
			continue
		start = min(start, r[i][0])
		end = max(end, r[i][1])
	return end - start + 1
t = int(input())
for _ in range(t):
	r1 = solve()
	print(r1)


import sys

def solve(ops, x, n):
	(mn, mx) = (x, x)
	for (l, r) in ops:
		if l <= mn and r >= mn:
			mn = l
		if l <= mx and r >= mx:
			mx = r
	return mx - mn + 1
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
cur = 1
for ti in range(T):
	(n, x, m) = [int(x) for x in IN[cur].split(' ')]
	ops = []
	for i in range(m):
		(l, r) = [int(x) for x in IN[cur + 1 + i].split(' ')]
		ops.append((l, r))
	result = solve(ops, x, n)
	print(result)
	cur += 1 + m


T = int(input())
for _ in range(T):
	(n, x, m) = input().split()
	n = int(n)
	x = int(x)
	m = int(m)
	count = 1
	x1 = x
	x2 = x
	for i in range(m):
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		if x1 >= l and x1 <= r:
			count += x1 - l
			x1 = l
		if x2 >= l and x2 <= r:
			count += r - x2
			x2 = r
	print(count)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, x, m) = invr()
	(q, w) = (x, x)
	for i in range(m):
		(l, r) = invr()
		if not (l > w or r < q):
			(q, w) = (min(q, l), max(w, r))
	print(w - q + 1)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

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

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def power_two(n):
	if n == 1:
		return True
	sttr = str(n)
	len_str = len(sttr)
	sttr = list(sttr)
	num = 0
	if len_str == 1 and sttr[len_str - 1] == '1':
		return False
	while len_str != 1 or sttr[len_str - 1] != '1':
		if (ord(sttr[len_str - 1]) - ord('0')) % 2 == 1:
			return False
		j = 0
		for i in range(len_str):
			num = num * 10 + (ord(sttr[i]) - ord('0'))
			if num < 2:
				if i != 0:
					sttr[j] = '0'
					j += 1
				continue
			sttr[j] = chr(num // 2 + ord('0'))
			j += 1
			num = num - num // 2 * 2
		len_str = j
	return True

def log_two(n):
	return math.log(n) / math.log(2)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


from sys import stdin
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
	(n, x, m) = list(map(int, stdin.readline().rstrip().split(' ')))
	currentRange = [x, x]
	for _ in range(m):
		(l, r) = list(map(int, stdin.readline().rstrip().split(' ')))
		if currentRange[1] < l or currentRange[0] > r:
			continue
		else:
			currentRange[0] = min(currentRange[0], l)
			currentRange[1] = max(currentRange[1], r)
	print(currentRange[1] - currentRange[0] + 1)


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


def solution():
	(n, x, m) = list(map(int, input().split()))
	lm = x
	rm = x
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if l <= rm and r >= lm:
			lm = min(l, lm)
			rm = max(r, rm)
	print(rm - lm + 1)
T = int(input())
for t in range(T):
	solution()


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


for tt in range(int(input())):
	(n, x, m) = map(int, input().strip().split())
	(al, ar) = (n, 0)
	flag = True
	Xc = [x, x]
	for mm in range(m):
		(l, r) = map(int, input().strip().split())
		if l <= Xc[0] and r >= Xc[0] or (r >= Xc[1] and l <= Xc[1]):
			flag = False
			if al > l:
				al = l
				Xc[0] = l
			if ar < r:
				ar = r
				Xc[1] = r
	if flag:
		print(1)
	else:
		print(ar - al + 1)


t = int(input())
while t > 0:
	(n, x, m) = map(int, input().split())
	left = right = x
	while m > 0:
		(l, r) = map(int, input().split())
		if r < left or l > right:
			m -= 1
			continue
		if l < left:
			left = l
		if r > right:
			right = r
		m -= 1
	print(right - left + 1)
	t -= 1


from math import ceil

def main():
	t = int(input())
	for i in range(t):
		(n, x, m) = map(int, input().split())
		left = right = x
		for i in range(m):
			(a, b) = map(int, input().split())
			if a <= left and b >= left:
				left = a
			if b >= right and a <= right:
				right = b
		print(right - left + 1)
main()


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


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	lr = []
	for _ in range(m):
		lr.append([int(x) for x in input().split()])
	l = x
	r = x
	for (l_, r_) in lr:
		if l_ <= r:
			r = max(r, r_)
		if r_ >= l:
			l = min(l, l_)
	print(r - l + 1)


t = int(input())
ans = [0] * t
for i in range(t):
	(n, x, m) = map(int, input().split())
	[Min, Max] = [x, x]
	for j in range(m):
		(l, r) = map(int, input().split())
		if l <= Min and Min <= r:
			Min = l
			Max = max(r, Max)
		elif l <= Max and Max <= r:
			Min = min(l, Min)
			Max = r
	ans[i] = Max - Min + 1
for i in range(t):
	print(int(ans[i]))


t = int(input())
i = 0
while i < t:
	summer = 0
	(n, x, m) = list(map(int, input().split()))
	j = 0
	ls = [[x, x]]
	while j < m:
		notFound = True
		(l, r) = list(map(int, input().split()))
		k = 0
		while k < len(ls) and notFound:
			if ls[k][0] >= l and ls[k][0] <= r or (ls[k][1] >= l and ls[k][1] <= r):
				notFound = False
			k += 1
		if not notFound:
			ls.append([l, r])
		j += 1
	ls.sort(key=lambda s: s[0])
	j = 0
	while j < len(ls):
		k = j + 1
		if k == len(ls):
			j += 1
		elif ls[k][0] <= ls[j][1]:
			ls[j][1] = max(ls[j][1], ls[k][1])
			ls[k:] = ls[k + 1:]
		else:
			j += 1
	summer = 0
	for l in ls:
		summer += l[1] - l[0] + 1
	print(summer)
	i += 1


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(l1, r1) = (x, x)
	for _ in range(m):
		(l, r) = map(int, input().split())
		if l < l1 and r > r1:
			(l1, r1) = (l, r)
		elif l <= r1 and r > r1:
			r1 = r
		elif l < l1 and r >= l1:
			l1 = l
	print(r1 - l1 + 1)


import sys
import math
import collections
from collections import deque
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7

def solve():
	(n, x, m) = list(map(int, stdin.readline().split()))
	x -= 1
	currL = x
	currR = x
	left = 0
	right = 0
	for i in range(m):
		(left, right) = list(map(int, stdin.readline().split()))
		left -= 1
		right -= 1
		if currL > right or currR < left:
			n -= 1
		else:
			currL = min(currL, left)
			currR = max(currR, right)
	print(currR - currL + 1)
t = 1
t = int(stdin.readline())
for _ in range(t):
	solve()


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


INT_MAX = 10 ** 30 + 7
MOD = 10 ** 9 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
for i in range(int(input())):
	(n, x, m) = INPUT()
	left = x
	right = x
	for i in range(m):
		(l, r) = INPUT()
		if l > right or r < left:
			continue
		left = min(left, l)
		right = max(right, r)
	print(right - left + 1)


t = int(input())
for i in range(t):
	(n, x, q) = map(int, input().split())
	l = x
	u = x
	for i in range(q):
		(p, q) = map(int, input().split())
		if p > u or q < l:
			continue
		l = min(p, l)
		u = max(u, q)
	print(u - l + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	shuru = True
	p = 0
	q = 0
	for i in range(m):
		(bam, dan) = map(int, input().split())
		if shuru:
			if x >= bam and x <= dan:
				shuru = False
				p = bam
				q = dan
		else:
			if bam <= p and dan >= p:
				p = bam
			if bam <= q and dan >= q:
				q = dan
	print(q - p + 1)


import sys
from typing import List
input = sys.stdin.readline
import math

def inp():
	return int(input())

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().strip().split())

def from_file(f):
	return f.readline

def solution(x, n, ops):
	xl = xr = x
	for (l, r) in ops:
		if xl <= l <= xr or l <= xl <= r:
			xl = min(xl, l)
			xr = max(xr, r)
	res = xr - xl + 1
	return res
t = inp()
for _ in range(t):
	(n, x, m) = invr()
	ops = []
	for _ in range(m):
		ops.append(invr())
	print(solution(x, n, ops))


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	left = 1000000001
	right = -1000000001
	for j in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r or l <= left <= r or r >= right >= l:
			left = min(left, l)
			right = max(right, r)
	if left <= n and right > 0:
		print(right - left + 1)
	else:
		print(1)


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


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


t = int(input())
for o in range(t):
	s = input().split()
	(n, k, m) = (int(s[0]), int(s[1]), int(s[2]))
	(l, r) = (k, k)
	for i in range(m):
		(x, y) = map(int, input().split())
		if x > r or y < l:
			continue
		r = max(r, y)
		l = min(l, x)
	print(r - l + 1)


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


t = int(input())
while t > 0:
	t = t - 1
	_ = input().split()
	n = int(_[0])
	x = int(_[1])
	m = int(_[2])
	a = [x, x]
	for i in range(0, m):
		_ = input().split()
		p = int(_[0])
		q = int(_[1])
		if (q < a[0]) | (p > a[1]):
			pass
		else:
			a[0] = min(p, a[0])
			a[1] = max(q, a[1])
	print(a[1] - a[0] + 1)


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	d = [[int(i) for i in input().split()] for j in range(m)]
	mini = x
	maxi = x
	cnt = 0
	r = []
	for i in d:
		if i[0] <= mini <= i[1] or i[0] <= maxi <= i[1]:
			mini = min(mini, i[0])
			maxi = max(maxi, i[1])
			r.extend([mini, maxi])
	if r:
		print(max(r) - min(r) + 1)
	else:
		print(1)


t = int(input())
for g in range(0, t):
	nxm = list(map(int, input().split()))
	n = nxm[0]
	x = nxm[1]
	m = nxm[2]
	mini = x
	maxi = x
	for i in range(0, m):
		lr = list(map(int, input().split()))
		l = lr[0]
		r = lr[1]
		if l < mini and r < mini:
			continue
		elif l > maxi and r > maxi:
			continue
		else:
			maxi = max(maxi, r)
			mini = min(mini, l)
	print(maxi - mini + 1)


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


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, x, m) = mapi()
	(pl, pr) = (x, x)
	for i in range(m):
		(l, r) = mapi()
		if l <= pl <= r or l <= pr <= r:
			pl = min(pl, l)
			pr = max(pr, r)
	print(pr - pl + 1)


for _ in range(int(input())):
	(k, x, m) = map(int, input().split())
	l = r = x
	for i in range(m):
		(p, q) = map(int, input().split())
		if p > r or q < l:
			continue
		else:
			l = min(l, p)
			r = max(r, q)
	print(r - l + 1)


T = int(input())
for _ in range(T):
	(n, x, m) = list(map(int, input().split()))
	(a, b) = (x, x)
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if r >= a and l <= b:
			a = min(l, a)
			b = max(r, b)
	print(b - a + 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 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)


def inter(l1, r1, l2, r2):
	l3 = max(l1, l2)
	r3 = min(r1, r2)
	return l3 <= r3
t = int(input())
for _ in range(t):
	(n, x, m) = (int(x) for x in input().split())
	l = x
	r = x
	for _ in range(m):
		(ll, rr) = (int(x) for x in input().split())
		if inter(l, r, ll, rr):
			l = min(l, ll)
			r = max(r, rr)
	print(r - l + 1)


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


def solve():
	(n, x, m) = map(int, input().split())
	lb = x
	ub = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a > ub or b < lb:
			continue
		lb = min(lb, a)
		ub = max(ub, b)
	print(ub - lb + 1)
t = int(input())
for loop in range(t):
	solve()


import sys
from math import *
from collections import defaultdict
from queue import deque
from heapq import heappush, heappop
lines = [line.strip() for line in sys.stdin.readlines()]
T = int(lines[0])
cur = 1
for t in range(T):
	(n, x, m) = map(int, lines[cur].split())
	ops = [list(map(int, line.split())) for line in lines[cur + 1:cur + 1 + m]]
	cur += 1 + m
	(lb, ub) = (x, x)
	for (a, b) in ops:
		if lb <= b:
			lb = min(lb, a)
		if ub >= a:
			ub = max(ub, b)
	print(ub - lb + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	pos = []
	for _ in range(m):
		(l, r) = map(int, input().split())
		if not pos:
			if l <= x <= r:
				pos.append([l, r])
		else:
			el = pos.pop(0)
			if l <= el[0] <= r or l <= el[1] <= r:
				el = [min(el[0], l), max(r, el[1])]
			pos.append(el)
	if pos:
		print(pos[0][1] - pos[0][0] + 1)
	else:
		print(1)


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, x, m) = [int(x) for x in inp().split()]
	high = x
	low = x
	for i in range(m):
		(l, r) = [int(x) for x in inp().split()]
		if l <= high <= r:
			high = max(high, r)
		if l <= low <= r:
			low = min(low, l)
	print(high - low + 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	L = x
	R = x
	for i in range(m):
		(l, r) = 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 _ in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	li = []
	l = 1010000000000
	r = 1
	flag = 0
	for i in range(m):
		(a, b) = [int(x) for x in input().split()]
		if flag == 0:
			if x >= a and x <= b:
				l = min(l, a)
				r = max(r, b)
				flag = 1
		else:
			if a >= l and a <= r:
				l = min(l, a)
				r = max(r, b)
			if b >= l and b <= r:
				l = min(l, a)
				r = max(r, b)
			if a >= l and b <= r:
				l = min(l, a)
				r = max(r, b)
			if a < l and b > r:
				l = min(l, a)
				r = max(r, b)
	if flag == 0:
		print(1)
	else:
		print(r - l + 1)


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


a = int(input())
for i in range(a):
	b = [int(x) for x in input().split()]
	minn = b[1]
	maxx = b[1]
	for j in range(b[2]):
		c = [int(x) for x in input().split()]
		if maxx >= c[0] and minn <= c[1]:
			minn = min(c[0], minn)
			maxx = max(c[1], maxx)
	print(maxx - minn + 1)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		nxm = list(map(int, input().split()))
		(n, x, m) = (nxm[0], nxm[1], nxm[2])
		ans = 1
		(mn, mx) = (-1, -1)
		for j in range(m):
			lr = list(map(int, input().split()))
			(l, r) = (lr[0], lr[1])
			if mn == -1:
				if x >= l and x <= r:
					(mn, mx) = (l, r)
					ans = r - l + 1
			elif mn != -1 and (r >= mn and l <= mx):
				ans = max(r, mx) - min(l, mn) + 1
				(mn, mx) = (min(l, mn), max(r, mx))
		print(ans)
main()


from sys import setrecursionlimit
from sys import stdin
readline = stdin.readline
setrecursionlimit(10 ** 5)
for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	(l, r) = (x, x)
	for i in range(m):
		(l1, l2) = map(int, readline().split())
		if l1 <= r and l2 >= l:
			(l, r) = (min(l, l1), max(r, l2))
	print(r - l + 1)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	(n, x, m) = map(int, input().split())
	(lf, rf) = (0, -1)
	for i in range(m):
		(l, r) = map(int, input().split())
		if rf - lf + 1 == 0:
			if l <= x and x <= r:
				lf = l
				rf = r
		elif not (l > rf or r < lf):
			if l < lf:
				lf = l
			if r > rf:
				rf = r
	print(max(rf - lf + 1, 1))


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	r1 = [x, x]
	for i in range(m):
		(l, r) = map(int, input().split())
		if l < r1[0] and (r >= r1[0] and r <= r1[1]):
			r1[0] = l
		elif l < r1[0] and r > r1[1]:
			r1[0] = l
			r1[1] = r
		elif r > r1[1] and (l >= r1[0] and l <= r1[1]):
			r1[1] = r
	print(r1[1] - r1[0] + 1)


t = int(input())
for _ in range(t):
	(n, k, m) = map(int, input().split())
	a = []
	for i in range(m):
		(x, y) = map(int, input().split())
		a.append((x, y))
	(l, r) = (k, k)
	for i in range(0, m):
		if l > a[i][1]:
			continue
		if r < a[i][0]:
			continue
		l = min(l, a[i][0])
		r = max(r, a[i][1])
	print(r - l + 1)


import time, math, bisect
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def solve():
	(n, x, m) = IP()
	(left, right) = (x, x)
	for i in range(m):
		(l, r) = IP()
		if r <= right and r >= left and (l <= left):
			left = l
		elif r >= right and l <= left:
			left = l
			right = r
		elif l >= left and l <= right and (r >= right):
			right = r
	print(right - left + 1)
t = II()
for i in range(t):
	solve()


def f(n, x, m, lr):
	xin = 0
	i = -1
	mi = 0
	ma = 0
	while xin == 0 and i < m - 1:
		i += 1
		if lr[i][0] <= x <= lr[i][1]:
			xin = 1
	if xin == 1:
		mi = lr[i][0]
		ma = lr[i][1]
		for k in range(i + 1, m):
			if mi <= lr[k][0] <= ma or mi <= lr[k][1] <= ma or lr[k][0] <= mi <= ma <= lr[k][1]:
				mi = min(mi, lr[k][0])
				ma = max(ma, lr[k][1])
	return ma - mi + 1
for i in range(int(input())):
	[n, x, m] = input().split(' ')
	(n, x, m) = (int(n), int(x), int(m))
	lr = []
	for i in range(m):
		lr.append(input().split(' '))
		(lr[i][0], lr[i][1]) = (int(lr[i][0]), int(lr[i][1]))
	print(f(n, x, m, lr))


y = int(input())
ans = []
for i in range(y):
	al = input().split()
	m = list(map(int, al))
	n = m[0]
	x = m[1]
	s = m[2]
	a = x
	b = x
	for j in range(s):
		al = input().split()
		m = list(map(int, al))
		l = m[0]
		r = m[1]
		if a != b:
			if l != r and (l <= b and b <= r or (l <= a and a <= r)):
				a = min(a, l)
				b = max(b, r)
		elif (l <= b and a <= r) and l != r:
			a = l
			b = r
	ans.append(b - a + 1)
for i in ans:
	print(i)


import math

def solve():
	(n, x, m) = map(int, input().split())
	in_last = True
	last = None
	ans = None
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r:
			if not ans:
				ans = [l, r]
			else:
				(tmpl, tmpr) = (ans[0], ans[1])
				ans = [min(l, tmpl), max(r, tmpr)]
		elif ans:
			a = max(l, ans[0])
			b = min(r, ans[1])
			if b >= a:
				(tmpl, tmpr) = (ans[0], ans[1])
				ans = [min(l, tmpl), max(r, tmpr)]
	if not ans:
		return 1
	return ans[1] - ans[0] + 1
t = int(input())
while t > 0:
	t -= 1
	print(solve())


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	flag = 0
	(l, r) = map(int, input().split())
	if x >= l and x <= r:
		flag = 1
		range_strt = l
		range_end = r
	for __ in range(m - 1):
		(l, r) = map(int, input().split())
		if flag == 1:
			if l >= range_strt and r > range_end and (l <= range_end):
				range_end = r
				range_strt = min(l, range_strt)
			elif l <= range_strt and r >= range_end:
				range_strt = l
				range_end = r
			elif l < range_strt and r >= range_strt and (r < range_end):
				range_strt = l
				range_end = max(r, range_end)
		elif x >= l and x <= r:
			flag = 1
			range_strt = l
			range_end = r
	if flag == 0:
		print(1)
	else:
		print(range_end - range_strt + 1)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ans = []
t = ini()
for _ in range(t):
	(n, x, m) = inm()
	(c, d) = (x, x)
	for _ in range(m):
		(l, r) = inm()
		if c >= l and c <= r:
			c = min(c, l)
		if l >= c and l <= d:
			d = max(d, r)
	ans.append(max(d - c + 1, 1))
out(ans)


ll = lambda : list(map(str, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
m = 1000000007
for _ in range(ii()):
	(n, x, m) = v()
	c = 0
	l = 0
	r = 0
	for i in range(m):
		(n1, n2) = v()
		if c == 0:
			if x >= n1 and x <= n2:
				c = 1
				l = n1
				r = n2
		else:
			if n1 <= l and n2 >= l:
				l = n1
			if n1 <= r and n2 >= r:
				r = n2
	print(r - l + 1)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	start = x
	end = x
	for j in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r:
			start = min(start, l)
			end = max(r, end)
		elif l <= start <= r or l <= end <= r:
			start = min(l, start)
			end = max(r, end)
	print(end - start + 1)


a = int(input())
for i in range(0, a):
	(n, x, m) = map(int, input().split())
	brr = []
	for i in range(0, m):
		brr.append(list(map(int, input().split())))
	minn = x
	maxx = x
	for i in range(0, m):
		if brr[i][0] <= minn and brr[i][1] >= minn:
			minn = min(brr[i][0], minn)
			maxx = max(brr[i][1], maxx)
		if brr[i][0] <= maxx and brr[i][1] >= maxx:
			minn = min(brr[i][0], minn)
			maxx = max(brr[i][1], maxx)
	print(maxx - minn + 1)


t = int(input())
for i in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	prev_left = -1
	prev_right = -1
	for j in range(m):
		(left, right) = [int(x) for x in input().split()]
		if left <= x <= right and prev_right == -1 and (prev_left == -1):
			prev_left = left
			prev_right = right
		elif prev_left <= left <= prev_right or prev_left <= right <= prev_right or left <= prev_left <= right or (left <= prev_right <= right):
			prev_left = min(prev_left, left)
			prev_right = max(prev_right, right)
	print(prev_right - prev_left + 1)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	lb = rb = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if r >= rb and l <= lb:
			lb = min(lb, l)
			rb = max(rb, r)
		elif r >= lb and r <= rb:
			lb = min(lb, l)
		elif l <= rb and l >= lb:
			rb = max(rb, r)
	print(rb - lb + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	ans = 0
	lm = x
	rm = x
	f = True
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= lm <= r or l <= rm <= r:
			if l <= x <= r and f:
				ans += 1
				f = False
			if lm > l:
				ans += lm - l
				lm = l
			if rm < r:
				ans += r - rm
				rm = r
	print(ans if ans else 1)


import sys
t = int(input())
while t:
	t = t - 1
	(n, x, q) = map(int, input().split())
	(a, b) = (x, x)
	while q:
		q -= 1
		(c, d) = map(int, input().split())
		if c <= b and d >= a:
			(a, b) = (min(a, c), max(b, d))
	print(b - a + 1)


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


for _ in range(int(input())):
	(n, x, m) = map(int, input('').split())
	start = n + 1
	end = -1
	for i in range(m):
		(l, r) = map(int, input('').split())
		if l >= start and l <= end or (r >= start and r <= end) or (l <= x and r >= x):
			start = min(start, l)
			end = max(end, r)
	if end == -1:
		print(1)
	else:
		print(end - start + 1)


import sys

def get():
	return int(sys.stdin.readline().strip())

def geti():
	return map(int, sys.stdin.readline().strip().split())

def getli():
	return list(map(int, sys.stdin.readline().strip().split()))
for _ in range(get()):
	(n, x, m) = geti()
	(mn, mx) = (x, x)
	for i in range(m):
		(l, r) = geti()
		if l > mx or r < mn:
			continue
		mx = max(mx, r)
		mn = min(mn, l)
	print(mx - mn + 1)


import sys, math
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, x, m) = map(int, sys.stdin.readline().split())
	start = -1
	end = -1
	for _ in range(m):
		(l, r) = map(int, sys.stdin.readline().split())
		if start == -1 and end == -1:
			if l <= x <= r:
				start = l
				end = r
		else:
			if r < start or l > end:
				continue
			if l < start:
				start = l
			if r > end:
				end = r
	print(end - start + 1)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, x, M) = MAP()
	mn = mx = x
	for i in range(M):
		(l, r) = MAP()
		if l <= mx and mn <= r:
			mn = min(mn, l)
			mx = max(mx, r)
	ans = mx - mn + 1
	print(ans)


import math

def main_function():
	test_cases = range(int(input()))
	for test_case in test_cases:
		(n, x, m) = [int(i) for i in input().split(' ')]
		current_l = x
		current_r = x
		for i in range(m):
			(l, r) = [int(j) for j in input().split(' ')]
			if l <= x <= r or current_l <= l <= current_r or current_l <= r <= current_r:
				if l < current_l:
					current_l = l
				if r > current_r:
					current_r = r
		print(current_r - current_l + 1)
main_function()


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	go = False
	o = 0
	p = 0
	for j in range(m):
		(a, b) = map(int, input().split())
		if go:
			if a < o and b > p:
				o = a
				p = b
			else:
				if o <= b <= p and a < o:
					o = a
				if o <= a <= p and b > p:
					p = b
		elif a <= x <= b:
			o = a
			p = b
			go = True
	print(p - o + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = list(map(int, input().strip().split()))
	b = 1
	for _ in range(m):
		(l, r) = list(map(int, input().strip().split()))
		if b:
			if l <= x and r >= x:
				start = l
				end = r
				b = 0
		elif l <= start and r >= end:
			start = l
			end = r
		elif l <= start and r >= start:
			start = l
		elif r >= end and l <= end:
			end = r
	if b:
		print(1)
	else:
		print(end - start + 1)


t = int(input())
for tc in range(t):
	s = input().split()
	(n, x, m) = (int(s[0]), int(s[1]), int(s[2]))
	a = x
	b = x
	for i in range(m):
		s1 = input().split()
		(x1, y1) = (int(s1[0]), int(s1[1]))
		if y1 < a:
			pass
		elif x1 > b:
			pass
		elif x1 < a:
			a = x1
			if y1 > b:
				b = y1
		elif y1 > b:
			b = y1
			if x1 < a:
				a = x1
	print(b - a + 1)


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	summ = 0
	minn = 0
	maxx = 0
	for j in range(m):
		(l, r) = map(int, input().split())
		if summ == 0 and x >= l and (r >= x):
			summ = r - l + 1
			minn = l
			maxx = r
		elif summ != 0 and minn > l and (maxx < r):
			summ += r - maxx + minn - l
			minn = l
			maxx = r
		elif summ != 0 and minn > l and (r >= minn):
			summ += minn - l
			minn = l
		elif summ != 0 and maxx < r and (l <= maxx):
			summ += r - maxx
			maxx = r
	if summ == 0:
		print(1)
	else:
		print(summ)


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


def overlap(start1, end1, start2, end2):
	return start1 <= start2 <= end1 or start1 <= end2 <= end1 or start2 <= start1 <= end2 or (start2 <= end1 <= end2)
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	curx = x
	cury = x
	for t in range(m):
		(x, y) = map(int, input().split())
		if overlap(curx, cury, x, y):
			curx = min(curx, x)
			cury = max(cury, y)
	print(cury - curx + 1)


import os
import sys
import io
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	answerstart = x
	answerend = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= answerstart <= b or a <= answerend <= b:
			answerstart = min(a, answerstart)
			answerend = max(b, answerend)
	print(answerend - answerstart + 1)


t = int(input())

def have_common(x, y, l, r):
	if y < l or r < x:
		return False
	else:
		return True
for k in range(t):
	(n, x, m) = map(int, input().split())
	s = 0
	e = 0
	found = 0
	for j in range(m):
		(l, r) = map(int, input().split())
		if found == 0 and (l <= x and x <= r):
			found = 1
			s = l
			e = r
		elif found == 1 and have_common(s, e, l, r):
			s = min(s, l)
			e = max(e, r)
	print(e - s + 1)


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


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd
from functools import reduce
from sys import stdin, stdout

def ncr(n, r):
	r = cn(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, x, m) = list(map(int, stdin.readline().split()))
	(L, R) = (x, x)
	for i in range(m):
		(l, r) = list(map(int, stdin.readline().split()))
		if not (l > R or r < L):
			L = min(L, l)
			R = max(R, r)
	print(R - L + 1)


cases = int(input())
for case in range(cases):
	(length, index, operations) = map(int, input().split())
	minimum = 0
	maximum = 0
	flag = 0
	for operation in range(operations):
		(left, right) = map(int, input().split())
		if flag == 0:
			if index >= left and index <= right:
				minimum = left
				maximum = right
				if left != right:
					flag = 1
				continue
		elif maximum < left or minimum > right:
			continue
		elif maximum >= left and minimum <= right:
			maximum = max(maximum, right)
			minimum = min(minimum, left)
	print(maximum - minimum + 1)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	(n, x, m) = spin()
	(l0, r0) = (x, x)
	for i in range(m):
		(l, r) = spin()
		if max(l, l0) <= min(r, r0):
			l0 = min(l, l0)
			r0 = max(r, r0)
	print(r0 - l0 + 1)


t = int(input())
for T 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 b < l or a > r:
			continue
		l = min(l, a)
		r = max(r, b)
	print(r - l + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(ll, ul) = (x, x)
	for i in range(m):
		(el, eu) = map(int, input().split())
		if el <= ll and eu >= ul:
			ll = min(ll, el)
			ul = max(eu, ul)
		if el <= ul:
			ul = max(eu, ul)
		if eu >= ll:
			ll = min(ll, el)
	print(ul - ll + 1)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		(l, r) = (x, x)
		for _ in range(m):
			(a, b) = map(int, input().split())
			if b < l or a > r:
				continue
			l = min(l, a)
			r = max(r, b)
		print(r - l + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def is_inter(l1, r1, l2, r2):
	if l1 >= l2 and l1 <= r2 or (r1 >= l2 and r1 <= r2) or (l2 >= l1 and l2 <= r1) or (r2 >= l1 and r2 <= r1):
		return True
	return False
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	(a, b) = (x, x)
	for j in range(m):
		(l, r) = map(int, input().split())
		if is_inter(a, b, l, r):
			a = min(a, l)
			b = max(b, r)
	print(b - a + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(start, end) = (x - 1, x - 1)
	for q in range(m):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		if b >= start and b <= end:
			if a < start:
				start = a
			if b > end:
				end = b
			continue
		if a >= start and a <= end:
			if a < start:
				start = a
			if b > end:
				end = b
			continue
		if start >= a and start <= b:
			if a < start:
				start = a
			if b > end:
				end = b
			continue
		if end >= a and end <= b:
			if a < start:
				start = a
			if b > end:
				end = b
			continue
	print(end - start + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	mn = n
	mx = 1
	val = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if val == 0:
			if x >= l and x <= r:
				val = 1
				mn = min(mn, l)
				mx = max(mx, r)
		elif x >= l and x <= r or (r >= mn and r <= mx) or (l >= mn and l <= mx) or (l <= mn and r >= mx):
			mn = min(mn, l)
			mx = max(mx, r)
	if val == 0:
		print(1)
	else:
		print(mx - mn + 1)


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


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

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

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(n, x, m) = mi()
	(lx, rx) = (x, x)
	for i in range(m):
		(l, r) = mi()
		if l <= lx <= r <= rx or r >= rx >= l >= lx or (l <= lx and rx <= r):
			(lx, rx) = (min(l, lx), max(r, rx))
	if lx == x == rx:
		print(1)
	else:
		print(rx - lx + 1)


t = int(input())
for q in range(t):
	(n, x, m) = map(int, input().split())
	ml = x
	mr = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if max(l, ml) <= min(r, mr):
			ml = min(ml, l)
			mr = max(mr, r)
	print(mr - ml + 1)


w = int(input())
for q in range(w):
	(n, x, m) = map(int, input().split())
	mat = []
	for i in range(m):
		grid = list(map(int, input().split()))
		mat.append(grid)
	else:
		y = x
		for i in range(m):
			mn = min(mat[i][0], mat[i][1])
			mx = max(mat[i][0], mat[i][1])
			if x >= mn and x <= mx or (y >= mn and y <= mx):
				if x > mn:
					x = mn
				if y < mx:
					y = mx
		print(y - x + 1)


def read_list():
	return list(map(int, input().split(' ')))
N = int(input())
for _ in range(N):
	(n, x, m) = read_list()
	s = [x, x]
	for _ in range(m):
		(l, r) = read_list()
		if not (r < s[0] or l > s[1]):
			s[0] = min(s[0], l)
			s[1] = max(s[1], r)
	print(s[1] - s[0] + 1)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, x, m) = map(int, input().split())
	a = x
	b = x
	v = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if l < a and r >= a:
			v = v + (a - l)
			a = l
		if r > b and l <= b:
			v = v + (r - b)
			b = r
	print(v + 1)


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)


R = lambda : map(int, input().split())
(t,) = R()
while t:
	(n, x, m) = R()
	y = x
	t -= 1
	while m:
		(l, r) = R()
		m -= 1
		if y >= l and r >= x:
			x = min(x, l)
			y = max(y, r)
	print(y - x + 1)


from math import ceil
T = int(input())
for t in range(T):
	(n, x, m) = [int(x) for x in input().split()]
	places = []
	L = x
	R = x
	for _ in range(m):
		(l, r) = [int(x) for x in input().split()]
		if l <= L and L <= r:
			L = l
			R = max(r, R)
		elif l <= R and R <= r:
			L = min(L, l)
			R = r
	print(R - L + 1)


def main():
	t = int(input())
	for i in range(0, t):
		(n, x, m) = map(int, input().split())
		lp = x - 1
		rp = x - 1
		for j in range(0, m):
			(l, r) = map(int, input().split())
			l -= 1
			r -= 1
			if r >= lp and l <= rp:
				lp = min(l, lp)
				rp = max(r, rp)
		print(rp - lp + 1)
main()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(a, b) = (x, x)
	for __ in range(m):
		(L, R) = map(int, input().split())
		if max(a, L) <= min(b, R):
			a = min(a, L)
			b = max(b, R)
	print(b - a + 1)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(n, x, m) = zzz()
	(a, b) = (x, x)
	for _ in range(m):
		(l, r) = zz()
		if b >= l and a <= r:
			a = min(a, l)
			b = max(b, r)
	print(b - a + 1)


import sys
sys.setrecursionlimit(1000000)
t = int(input())
for T in range(t):
	[n, x, m] = list(map(int, input().split(' ')))
	low = x
	high = x
	for i in range(m):
		[l, r] = list(map(int, input().split(' ')))
		if l <= low <= r or l <= high <= r:
			if low > l:
				low = l
			if high < r:
				high = r
	print(high - low + 1)


t = int(input())
for test in range(t):
	(n, s, m) = [int(x) for x in input().split()]
	ans = [s, s]
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		if r >= ans[0] and r <= ans[1] or (l >= ans[0] and l <= ans[1]) or (l <= ans[0] and r >= ans[1]):
			ans[0] = min(l, ans[0])
			ans[1] = max(r, ans[1])
	delta = ans[1] - ans[0] + 1
	print(delta)


def solve():
	(_, x, m) = map(int, input().split(' '))
	left = x
	right = x
	for _ in range(m):
		(st, end) = map(int, input().split(' '))
		if st <= left <= end or st <= right <= end:
			left = min(left, st)
			right = max(right, end)
	return right - left + 1
T = int(input())
ans = []
for _ in range(T):
	ans.append(solve())
for a in ans:
	print(a)


T = int(input())
for t in range(T):
	(n, x, m) = [int(i) for i in input().split()]
	(cur_left, cur_right) = (x, x)
	for i in range(m):
		(p, q) = [int(j) for j in input().split()]
		if q < cur_left or p > cur_right:
			continue
		else:
			cur_left = min(cur_left, p)
			cur_right = max(cur_right, q)
	print(cur_right - cur_left + 1)


t = int(input())
for test in range(t):
	(n, x, m) = input().split()
	(n, x, m) = (int(n), int(x), int(m))
	L = x
	H = x
	for i in range(m):
		(l_, h_) = input().split()
		(l_, h_) = (int(l_), int(h_))
		if h_ > H:
			if l_ <= H:
				H = h_
		if l_ < L:
			if h_ >= L:
				L = l_
	print(H - L + 1)


from math import *

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]

def r3(t):
	return [t(i) for i in input()]
for _ in range(r1(int)):
	(n, x, m) = r2(int)
	x -= 1
	cl = x
	cr = x
	for i in range(m):
		(l, r) = r2(int)
		l -= 1
		r -= 1
		if l > cr or r < cl:
			pass
		else:
			cr = max(cr, r)
			cl = min(cl, l)
	print(cr - cl + 1)


def merge(a, b, L, R):
	assert a <= b and L <= R
	if R < a or b < L:
		return (a, b)
	if a <= L and R <= b:
		return (a, b)
	return (min(a, L), max(b, R))

def solve():
	(N, X, M) = [int(x) for x in input().split()]
	(mi, ma) = (X, X)
	for _ in range(M):
		(Li, Ri) = [int(x) for x in input().split()]
		(mi, ma) = merge(mi, ma, Li, Ri)
	print(ma - mi + 1)
T = int(input())
for _ in range(T):
	solve()


import sys
read = sys.stdin.buffer.readline
cin = lambda : int(read())
mi = lambda : map(int, read().split())
for _ in range(cin()):
	(n, x, m) = mi()
	ans = 0
	(l, r) = (x, x)
	for i in range(m):
		(u, v) = mi()
		if v < l or u > r:
			continue
		else:
			l = min(l, u)
			r = max(r, v)
	print(r - l + 1)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	l = y
	u = y
	for i in range(z):
		(a, b) = map(int, input().split())
		if a <= l <= b or a <= u <= b:
			l = min(l, a)
			u = max(u, b)
	print(u - l + 1)


import math
from sys import stdin, stdout
from heapq import heapify, heappop, heappush
T = int(stdin.readline())
for i in range(T):
	(n, x, m) = list(map(int, stdin.readline().split()))
	cur = [x, x]
	for i in range(m):
		(a, b) = list(map(int, stdin.readline().split()))
		if a > cur[-1] or b < cur[0]:
			continue
		cur[-1] = max(b, cur[-1])
		cur[0] = min(a, cur[0])
	print(cur[-1] - cur[0] + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = list(map(int, input().split(' ')))
	rng = [x, x]
	for i in range(m):
		(l, r) = list(map(int, input().split(' ')))
		if not (l > rng[1] or r < rng[0]):
			rng[0] = min(l, rng[0])
			rng[1] = max(r, rng[1])
	print(rng[1] - rng[0] + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(lower, upper) = (x, x)
	for i in range(m):
		(l1, r1) = map(int, input().split())
		if r1 < lower or l1 > upper:
			continue
		lower = min(lower, l1)
		upper = max(upper, r1)
	print(upper - lower + 1)


def un(x, y):
	(a1, a2) = x
	(b1, b2) = y
	if b1 > a2:
		return (a1, a2)
	if b2 < a1:
		return (a1, a2)
	return (min(a1, b1), max(a2, b2))
t = int(input())
for tt in range(t):
	(n, x, m) = [int(z) for z in input().split()]
	curr = (x, x)
	while m > 0:
		(l, r) = [int(z) for z in input().split()]
		m -= 1
		curr = un(curr, (l, r))
	print(curr[1] - curr[0] + 1)


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


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)


t = int(input())
for _ in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	l = x
	r = x
	for i in range(m):
		(start, end) = [int(x) for x in input().split()]
		if l <= start <= r or l <= end <= r or start <= l <= end or (start <= l <= end):
			l = min(l, start)
			r = max(r, end)
	print(r - l + 1)


def solve():
	global N, M, X, LR
	S = (X, X)
	for (l, r) in LR:
		(ls, rs) = S
		if rs >= l and rs <= r or (ls <= r and ls >= l):
			S = (min(l, ls), max(r, rs))
	return S[1] - S[0] + 1
import os
for _ in range(int(input())):
	(N, X, M) = map(int, input().split())
	LR = list()
	for _ in range(M):
		LR.append(tuple(map(int, input().split())))
	sol = solve()
	print(sol)


t = int(input())
for i in range(t):
	(n, x, m) = input().split()
	n = int(n)
	x = int(x)
	m = int(m)
	ma = x
	mi = x
	for i in range(m):
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		if mi <= r:
			if mi > l:
				mi = l
		if ma >= l:
			if ma < r:
				ma = r
	print(ma - mi + 1)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from collections import Counter
from bisect import bisect_left
import sys
from queue import PriorityQueue
mod = 1000000007

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

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

def main():
	for t in range(I()):
		myCode()
main()


t = int(input())
for cas in range(t):
	(n, x, m) = map(int, input().split())
	(lt, rt) = (x, x)
	for j in range(m):
		(a, b) = map(int, input().split())
		if a <= lt <= b or a <= rt <= b:
			(lt, rt) = (min(lt, a), max(rt, b))
	print(rt - lt + 1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	can_1 = x
	can_2 = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if l <= can_1 and can_1 <= r or (l <= can_2 and can_2 <= r):
			can_1 = min(can_1, l)
			can_2 = max(can_2, r)
	print(can_2 - can_1 + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(mn, mx) = (x, x)
	for _ in range(m):
		(l, r) = map(int, input().split())
		if mn > r and mx > r or (mn < l and mx < l):
			continue
		mn = min(mn, l)
		mx = max(mx, r)
	print(mx - mn + 1)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		(n, x, m) = get_int_input_arr()
		left_limit = x
		right_limit = x
		for _ in range(m):
			(l, r) = get_int_input_arr()
			if right_limit < l or r < left_limit:
				continue
			else:
				left_limit = min(left_limit, l)
				right_limit = max(r, right_limit)
		cout << right_limit - left_limit + 1 << endl

def main():
	solve()
main()


import math
import sys
input = sys.stdin.readline
t = int(input())
for cs in range(t):
	(n, x, m) = map(int, input().split())
	(l, r) = (x, x)
	for i in range(m):
		(p, q) = map(int, input().split())
		if r < p or q < l:
			continue
		l = min(l, p)
		r = max(r, q)
	print(r - l + 1)


T = int(input())
while T:
	(n, x, m) = map(int, input().split())
	L = n
	R = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x and x <= r:
			L = min(L, l)
			R = max(R, r)
		else:
			if L <= r:
				L = min(L, l)
			if R >= l:
				R = max(R, r)
	print(max(R - L + 1, 1))
	T = T - 1


for _ in ' ' * int(input()):
	(n, x, m) = map(int, input().split())
	f = 0
	ans = 0
	left = -1
	right = -1
	rright = -1
	rleft = -1
	for i in range(m):
		(l, r) = map(int, input().split())
		if f == 0:
			if l <= x <= r:
				f = 1
				rleft = l
				rright = r
				left = l
				right = r
		elif rleft <= r or rright >= l:
			if left <= r and right >= l:
				left = min(left, l)
				right = max(right, r)
			elif left <= r:
				left = min(left, l)
			else:
				right = max(r, right)
			rleft = l
			rright = r
		else:
			break
	print(right - left + 1 if rleft != -1 else 1)


import sys
import heapq
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, sys.stdin.readline().split())
	table = []
	for _ in range(m):
		table.append(list(map(int, sys.stdin.readline().split())))
	ans = [None, None]
	for i in range(m):
		if ans[0] == None:
			if table[i][0] <= x <= table[i][1]:
				ans = [table[i][0], table[i][1]]
		else:
			if ans[0] <= table[i][1]:
				ans[0] = min(ans[0], table[i][0])
			if ans[1] >= table[i][0]:
				ans[1] = max(ans[1], table[i][1])
	if ans[0] == None:
		print(1)
	else:
		print(ans[1] - ans[0] + 1)


def main():
	T = int(input())
	for _ in range(T):
		(N, X, M) = map(int, input().split())
		(l, r) = (-1, -1)
		found = False
		for _ in range(M):
			(x, y) = map(int, input().split())
			if found == False and x <= X and (X <= y):
				(l, r) = (x, y)
				found = True
			elif found == True:
				if y >= l and y <= r:
					if x < l:
						l = x
				elif x >= l and x <= r:
					if y > r:
						r = y
				elif x <= l and y >= r:
					(l, r) = (x, y)
		print(r - l + 1)
main()


def main():
	t = int(input())
	for __ in range(t):
		(n, x, m) = map(int, input().split())
		(l, r) = (x, x)
		for i in range(m):
			(L, R) = map(int, input().split())
			if L <= r and R >= l:
				l = min(l, L)
				r = max(r, R)
		print(r - l + 1)
main()


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


for tesCase in range(int(input())):
	(n, x, m) = map(int, input().split())
	(l, r, flag) = (0, 0, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		if flag == 0:
			if a <= x <= b:
				l = a
				r = b
				flag = 1
		else:
			if a <= l <= b:
				l = a
			if a <= r <= b:
				r = b
	print(r - l + 1)


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, x, m) = invr()
	(nowL, nowR) = invr()
	if x < nowL or x > nowR:
		nowL = -1
		nowR = -1
	for i in range(1, m):
		(l, r) = invr()
		if nowL == -1 and nowR == -1:
			if x >= l and x <= r:
				nowL = l
				nowR = r
		elif nowR >= l and nowR <= r:
			nowR = r
			nowL = min(l, nowL)
		elif nowL >= l and nowL <= r:
			nowL = l
			nowR = max(r, nowR)
	if nowL == -1 and nowR == -1:
		print(1)
	else:
		print(nowR - nowL + 1)


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


for ii in range(int(input())):
	(n, x, m) = map(int, input().split())
	mini = x
	maxi = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if maxi < l or mini > r:
			pass
		else:
			mini = min(l, mini)
			maxi = max(r, maxi)
	print(maxi - mini + 1)


def solve():
	(n, x, m) = map(int, input().split())
	l = x
	r = x
	for i in range(m):
		(li, ri) = map(int, input().split())
		if ri < l or li > r:
			continue
		else:
			l = min(l, li)
			r = max(r, ri)
	print(r - l + 1)
t = int(input())
for _ in range(t):
	solve()


for srsewresrw in range(int(input())):
	(n, x, m) = map(int, input().split())
	ot = [x - 1, x]
	for i in range(m):
		(a, b) = map(int, input().split())
		a -= 1
		if b <= ot[0] or a >= ot[1]:
			pass
		elif a <= ot[0] and b >= ot[1]:
			ot[1] = b
			ot[0] = a
		elif b > ot[1]:
			ot[1] = b
		elif a < ot[0]:
			ot[0] = a
	print(ot[1] - ot[0])


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()


T = int(input())
for t in range(T):
	(n, x, m) = map(int, input().split())
	intervals = [list(map(int, input().split())) for _ in range(m)]
	(low, high) = (x, x)
	for (li, ri) in intervals:
		if li <= low <= ri or li <= high <= ri:
			low = min(li, low)
			high = max(ri, high)
	print(high - low + 1)


def solve():
	(n, x, m) = map(int, input().split())
	ll = x
	rr = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= rr <= b:
			rr = b
		if a <= ll <= b:
			ll = a
	print(rr - ll + 1)
for i in range(int(input())):
	solve()


t = int(input())
for z in range(t):
	(n, x, m) = list(map(int, input().split()))
	a = x
	b = x
	c = 1
	for i in range(m):
		(y, z) = list(map(int, input().split()))
		if y <= a and z >= b:
			a = y
			b = z
		elif z >= b and y <= b:
			b = z
		elif y <= a and z >= a:
			a = y
	c = max(c, b - a + 1)
	print(c)


def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
import math

def bubble_sort(c):
	n = len(c)
	for i in range(n):
		already_sorted = True
		for j in range(n - i - 1):
			if c[j][0] < c[j + 1][0]:
				(c[j][0], c[j + 1][0]) = (c[j + 1][0], c[j][0])
				already_sorted = False
			if c[j][0] == c[j + 1][0]:
				if c[j][1] > c[j + 1][1]:
					(c[j][1], c[j + 1][1]) = (c[j + 1][1], c[j][1])
		if already_sorted:
			break
	return c

def fun(l, r):
	if l > r:
		return
	m = (l + r) // 2
	c.append([l - r, m])
	fun(l, m - 1)
	fun(m + 1, r)
t = int(input())
while t:
	t -= 1
	(n, x, m) = map(int, input().split())
	ss = x
	ee = x
	cnt = 0
	while m:
		m -= 1
		(a, b) = map(int, input().split())
		if ee < a:
			continue
		elif ss > b:
			continue
		elif ss <= a and ee >= b:
			continue
		elif ss <= a and ee <= b:
			ee = b
		elif ss >= a and ee >= b:
			ss = a
		elif ss >= a and ee <= b:
			ss = a
			ee = b
	print(ee - ss + 1)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, x, m) = [int(x) for x in inp().split()]
	ans = 1
	lower = x
	upper = x
	for i in range(m):
		(l, r) = [int(x) for x in inp().split()]
		if l <= lower <= r:
			lower = min(l, lower)
		if l <= upper <= r:
			upper = max(r, upper)
	print(abs(lower - upper) + 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)


t = int(input())
while t:
	t -= 1
	(n, x, m) = map(int, input().split())
	s = x
	e = x
	cnt = 0
	while m:
		m -= 1
		(a, b) = map(int, input().split())
		if e < a:
			continue
		elif s > b:
			continue
		elif s <= a and e >= b:
			continue
		elif s <= a and e <= b:
			e = b
		elif s >= a and e >= b:
			s = a
		elif s >= a and e <= b:
			s = a
			e = b
	print(e - s + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(mini, maxi) = (x, x)
	f = 0
	while m > 0:
		m -= 1
		(l, r) = map(int, input().split())
		if f == 0:
			if l <= x and x <= r:
				f = 1
				maxi = max(maxi, r)
				mini = min(mini, l)
		elif f == 1:
			if mini >= l and r >= mini:
				mini = min(mini, l)
			if maxi <= r and l <= maxi:
				maxi = max(maxi, r)
	print(maxi - mini + 1)


t = int(input())
for i in range(t):
	line = [int(x) for x in input().split()]
	n = line[0]
	x = line[1]
	m = line[2]
	r = x
	l = x
	for j in range(m):
		pair = [int(x) for x in input().split()]
		if pair[0] <= r <= pair[1] or pair[0] <= l <= pair[1]:
			edges = [pair[0], r, pair[1], l]
			edges.sort()
			l = edges[0]
			r = edges[3]
	print(r - l + 1)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	mn = x
	mx = x
	ans = 1
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= mn <= b or a <= mx <= b:
			mn = min(a, mn)
			mx = max(b, mx)
			ans = abs(mn - mx) + 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, x, m) = (int(i) for i in input().split())
	lt = n
	rt = 0
	i = 0
	while i < m:
		(l, r) = (int(i) for i in input().split())
		i += 1
		if x in range(l, r + 1):
			lt = l
			rt = r
			break
	while i < m:
		(l, r) = (int(i) for i in input().split())
		i += 1
		if l in range(lt, rt + 1) or r in range(lt, rt + 1) or lt in range(l, r + 1) or (rt in range(l, r + 1)):
			lt = min(lt, l)
			rt = max(rt, r)
	print(max(rt - lt + 1, 1))


from sys import stdin, stdout
for t in range(int(stdin.readline())):
	(n, x, m) = map(int, stdin.readline().split())
	a = [x, x]
	flag = 0
	for i in range(m):
		(u, v) = map(int, stdin.readline().split())
		if u <= a[0] and v >= a[0]:
			a[0] = u
		if v >= a[1] and u <= a[1]:
			a[1] = v
	stdout.write(str(a[1] - a[0] + 1) + '\n')


tr = int(input())
for i in range(tr):
	(n, x, m) = map(int, input().split())
	p = x
	q = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if q <= r:
			if q > l:
				q = l
		if p >= l:
			if p < r:
				p = r
	print(p - q + 1)


import sys
import math
import collections

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	(n, x, m) = get_ints()
	l_gb = x
	r_gb = x
	for i in range(m):
		(l, r) = get_ints()
		if l <= x and x <= r or (l_gb <= l and l <= r_gb) or (r >= l_gb and r <= r_gb):
			l_gb = min(l_gb, l)
			r_gb = max(r, r_gb)
	print(r_gb - l_gb + 1)


import math
import sys
import itertools
import random

def lcm(x, y):
	return x * y // math.gcd(x, y)

def hcf(x, y):
	return math.gcd(x, y)

def primes(n):
	prime = [True for _ in range(0, n + 1)]
	res = []
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[p] = False
		p += 1
	for i in range(0, n + 1):
		if prime[i] == True:
			res.append(i)
	return res

def primeFactors(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n //= 2
	for i in range(3, math.sqrt(n) + 1, 2):
		while n % i == 0:
			res.append(i)
			n //= i
	if n > 2:
		res.append(n)
	return res
for _ in range(0, int(input())):
	(n, x, m) = map(int, input().strip().split())
	q = []
	for __ in range(0, m):
		q.append(list(map(int, input().strip().split())))
	lower = x
	upper = x
	for i in q:
		if i[1] <= upper and i[1] >= lower and (i[0] <= lower):
			lower = i[0]
		elif i[0] <= upper and i[0] >= lower and (i[1] >= upper):
			upper = i[1]
		elif i[0] <= lower and i[1] > upper:
			lower = i[0]
			upper = i[1]
		elif i[0] >= lower and i[1] <= upper:
			pass
	print(upper - lower + 1)


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


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	start = False
	prevL = 0
	prevR = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if x >= l and x <= r and (not start):
			prevL = l
			prevR = r
			start = True
		elif (prevL <= l and prevR >= l or (prevL <= r and prevR >= r)) or ((l <= prevL and r >= prevR) and start):
			prevL = min(l, prevL)
			prevR = max(r, prevR)
	print(prevR - (prevL - 1))


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


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	(n, x, m) = list(map(int, input().split()))
	l = x
	r = x
	for j in range(0, m):
		(a, b) = list(map(int, input().split()))
		if a <= l <= b:
			l = a
		if a <= r <= b:
			r = b
	print(r - l + 1)
t = int(input())
for i in range(0, t):
	main()


import sys

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	(n, x, m) = idata()
	(x, y) = (x, x)
	for i in range(m):
		(l, r) = idata()
		if l <= y and r >= x:
			(x, y) = (min(l, x), max(y, r))
	print(y - x + 1)
	return
for ______ in range(int(ii())):
	solve_of_problem()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = [x, x]
	ans = [x, x]
	for i in range(m):
		(l, r) = map(int, input().split())
		if not (r < a[0] or a[1] < l):
			ans = [min(a[0], l), max(r, a[1])]
			a = ans
	print(ans[1] - ans[0] + 1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	(n, x, m) = l()
	curr = [x, x]
	for i in range(m):
		(a, b) = l()
		if a <= curr[0] and curr[0] <= b or (a <= curr[1] and curr[1] <= b) or (curr[0] <= a and a <= curr[1]) or (curr[0] <= b and b <= curr[1]):
			curr[0] = min(curr[0], a)
			curr[1] = max(curr[1], b)
	print(curr[1] - curr[0] + 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)


for _ in range(int(input())):
	a = input().split(' ')
	n = int(a[0])
	x = int(a[1])
	m = int(a[2])
	vals = []
	xinterval = 0
	left = n
	right = -1
	for i in range(m):
		a = input().split(' ')
		li = int(a[0])
		ri = int(a[1])
		if xinterval == 1:
			if li < left and left <= ri:
				left = li
			if ri > right and li <= right:
				right = ri
		elif li <= x <= ri and xinterval == 0:
			xinterval = 1
			left = li
			right = ri
	print(max(1, right - left + 1))


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(n, x, m) = [int(i) for i in input().split(' ')]
		start = x
		end = x
		flag = False
		for i in range(m):
			(l, r) = [int(i) for i in input().split(' ')]
			if not flag and l <= x <= r:
				start = l
				end = r
				flag = True
			elif flag and (not (l > end or start > r)):
				start = min(start, l)
				end = max(end, r)
		print(end - start + 1)
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, x, m) = list(map(int, input().split()))
		se = [x, x]
		for i in range(m):
			(s, e) = list(map(int, input().split()))
			(prevs, preve) = se
			(news, newe) = (prevs, preve)
			if not (preve < s or prevs > e):
				news = min(prevs, s)
				newe = max(preve, e)
			se = [news, newe]
		yield (se[1] - se[0] + 1)
t = int(input())
ans = gift()
print(*ans, sep='\n')


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(x, y) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r or l <= y <= r:
			x = min(l, x)
			y = max(r, y)
	ans = y - x + 1
	stdout.write(str(ans) + '\n')


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


def solve():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().strip().split())
		(l, r) = (x, x)
		for i in range(m):
			(li, ri) = map(int, input().strip().split())
			if li <= l and ri >= r:
				l = li
				r = ri
			elif li > l and ri < l or li > r or ri < l:
				pass
			elif li < l and ri < r:
				l = li
			elif li > l and ri > r:
				r = ri
		print(r - l + 1)
solve()


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


from sys import stdin
input = stdin.readline
for Ti in range(int(input().strip())):
	(n, x, m) = [int(x) for x in input().strip().split()]
	(s, e) = (x, x)
	for mi in range(m):
		(a, b) = [int(x) for x in input().strip().split()]
		if a <= s <= b or a <= e <= b:
			s = min(s, a)
			e = max(e, b)
	print(e - s + 1)


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


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	cur = [x, x]
	segs = [list(map(int, input().split())) for i in range(m)]
	for j in range(m):
		if segs[j][0] <= cur[0] and cur[1] <= segs[j][1]:
			cur = segs[j]
		elif segs[j][0] <= cur[0] <= segs[j][1] <= cur[1]:
			cur[0] = segs[j][0]
		elif cur[0] <= segs[j][0] <= cur[1] <= segs[j][1]:
			cur[1] = segs[j][1]
	print(cur[1] - cur[0] + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	L = []
	for _ in range(m):
		(l, r) = map(int, input().split())
		if len(L) == 0 and (x < l or r < x):
			continue
		if len(L) == 0:
			L.append((l, r))
			continue
		flag = True
		if l <= x <= r:
			flag = False
		for t in L:
			if l <= t[0] <= r or l <= t[1] <= r:
				flag = False
		if flag:
			continue
		L.append((l, r))
	L.sort()
	ans = 0
	prev = -1
	for t in L:
		if prev >= t[0]:
			if prev >= t[1]:
				continue
			else:
				ans += t[1] - prev
				prev = t[1]
		else:
			ans += t[1] - t[0] + 1
			prev = t[1]
	print(max(1, ans))


def main():
	import sys
	sys.setrecursionlimit(10 ** 6)
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		(n, x, m) = [int(x) for x in input().strip().split()]
		(mini, maxi) = (x, x)
		for _ in range(m):
			(l, r) = [int(x) for x in input().strip().split()]
			if mini <= r and l <= maxi:
				(mini, maxi) = (min(mini, l), max(maxi, r))
		print(maxi - mini + 1)
main()


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


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


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	(n, x, m) = invr()
	(lk, rk) = (x, x)
	ans = 0
	(l, r) = ([None] * m, [None] * m)
	for j in range(m):
		(l[j], r[j]) = invr()
		if l[j] <= lk <= r[j]:
			lk = l[j]
		if r[j] >= rk >= l[j]:
			rk = r[j]
	ans = rk - lk + 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	low = -float('inf')
	high = float('inf')
	for i in range(m):
		(l, h) = map(int, input().split())
		if low == -float('inf') and high == float('inf'):
			if l <= x <= h:
				low = l
				high = h
		else:
			if l <= low <= h:
				low = l
			if l <= high <= h:
				high = h
	if low != -float('inf'):
		print(high - low + 1)
	else:
		print(1)


import sys
from bisect import bisect_left, bisect_right
INF = 1 << 60
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	left = x - 1
	right = x - 1
	for j in range(m):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		if r < left or right < l:
			continue
		left = min(left, l)
		right = max(right, r)
	ans = right - left + 1
	print(ans)


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


from sys import *
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	c = 0
	d = 0
	for _ in range(m):
		(a, b) = map(int, input().split())
		if c == 0:
			if a <= x <= b:
				c = a
				d = b
		elif a <= c <= b or a <= d <= b:
			c = min(a, c)
			d = max(b, d)
	if c == 0:
		print(1)
	else:
		print(d - c + 1)


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	q = x
	p = x
	for j in range(m):
		(a, b) = map(int, input().split())
		if b > q and a < p:
			p = a
			q = b
		elif b >= p and a < p:
			p = a
		elif a <= q and b > q:
			q = b
	print(q - p + 1)


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

def readn():
	return int(input())
for _ in range(readn()):
	(n, x, m) = readintlst()
	one = [x, x]
	ans = 1
	for _ in range(m):
		(l, r) = readintlst()
		if max(l, one[0]) <= min(r, one[1]):
			one = [min(one[0], l), max(one[1], r)]
	print(one[1] - one[0] + 1)


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


(T,) = map(int, input().split())
for _ in range(T):
	(N, x, M) = map(int, input().split())
	(s, e) = (x, x)
	for _ in range(M):
		(l, r) = map(int, input().split())
		if not (r < s or e < l):
			(s, e) = (min(s, l), max(e, r))
	print(e - s + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	s = [x, x]
	for __ in range(m):
		(l, r) = map(int, input().split())
		if l > s[1]:
			continue
		if r < s[0]:
			continue
		(s[0], s[1]) = (min(l, s[0]), max(r, s[1]))
	print(s[1] - s[0] + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	flag = False
	for _ in range(m):
		(l, r) = map(int, input().split())
		if flag:
			if l <= R[0] and R[1] <= r or (l <= R[0] and R[0] <= r and (r <= R[1])) or (R[0] <= l and l <= R[1] and (R[1] <= r)):
				R[0] = min(l, R[0])
				R[1] = max(r, R[1])
			continue
		elif x >= l and r >= x:
			flag = True
			R = [l, r]
	if flag:
		print(R[1] - R[0] + 1)
	else:
		print(1)


I = lambda : map(int, input().split())
for _ in [0] * int(input()):
	(n, x, m) = I()
	mi = n + 1
	ma = ff = 0
	for _ in [0] * m:
		(l, r) = I()
		if ff == 0 and l - 1 < x < r + 1:
			ff = 1
		if ff == 1:
			if l < mi and mi <= r <= ma:
				mi = l
			elif r > ma and ma >= l >= mi:
				ma = r
			elif r > ma and l < mi:
				ma = r
				mi = l
	x = ma - mi + 1
	if x < 0:
		x = 1
	print(x)


def main():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		x = (-1, x)
		for i in range(m):
			(x1, y1) = map(int, input().split())
			if x[0] == -1 and x1 <= x[1] <= y1:
				x = (x1, y1)
			elif x1 <= x[0] <= x[1] <= y1:
				x = (x1, y1)
			elif x[0] <= x1 <= x[1] <= y1:
				x = (x[0], y1)
			elif x1 <= x[0] <= y1 <= x[1]:
				x = (x1, x[1])
		print(x[1] - x[0] + 1 if x[0] != -1 else 1)
main()


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


w = lambda : list(map(int, input().split()))
for k in '0' * int(input()):
	(n, y, m) = w()
	(a, b) = (y, y)
	for i in '0' * m:
		(s, p) = w()
		if b >= s and a <= p:
			a = min(s, a)
			b = max(b, p)
	print(b - a + 1)


import collections

def read():
	return input().strip()

def readInt():
	return int(input().strip())

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

def solve(n, x, m, indices):
	(left, right) = (n, -1)
	for (l, r) in indices:
		if l <= x <= r:
			left = min(left, l)
			right = max(right, r)
		if left != n and l <= left <= r:
			left = min(l, left)
		if right != -1 and l <= right <= r:
			right = max(r, right)
	if left == n or right == -1:
		return 1
	return right - left + 1
t = readInt()
for i in range(t):
	indices = []
	[n, x, m] = readList()
	for _ in range(m):
		indices.append(readList())
	print(solve(n, x, m, indices))


t = int(input())
for case in range(t):
	(n, x, m) = [int(s) for s in input().split(' ')]
	limits = [x, x]
	for line in range(m):
		(l, r) = [int(s) for s in input().split(' ')]
		if limits[0] <= r <= limits[1]:
			limits[0] = min(limits[0], l)
		if limits[0] <= l <= limits[1]:
			limits[1] = max(limits[1], r)
		if limits[0] >= l and limits[1] <= r:
			limits = [l, r]
	print(limits[1] - limits[0] + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a2 = a1 = x
	ll = []
	rr = []
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= a2 <= r or l <= a1 <= r:
			a1 = min(a1, l)
			a2 = max(a2, r)
	rr = sorted(rr, key=lambda f: f[1])
	print(abs(a1 - a2) + 1)


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(n, x, m) = list(map(int, sys.stdin.readline().rstrip().split()))
	left = x
	right = x
	for _ in range(m):
		(i, j) = list(map(int, sys.stdin.readline().rstrip().split()))
		if not (j < left or right < i or (left <= i and j <= right)):
			if i < left:
				left = i
			if right < j:
				right = j
	print(right - left + 1)


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

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

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(n, x, m) = iis()
	ranges = [[x, x]]
	for i in range(m):
		(l, r) = iis()
		for j in ranges:
			if l <= j[1] and r >= j[0]:
				ranges.append([l, r])
				break
	final_ans = []
	for r in ranges:
		can = True
		for r2 in final_ans:
			if r[1] >= r2[1] and r[0] <= r2[1]:
				r2[1] = r[1]
				can = False
			if r[0] <= r2[0] and r[1] >= r2[0]:
				r2[0] = r[0]
				can = False
			if r[0] >= r2[0] and r[1] <= r2[1]:
				can = False
			if not can:
				break
		if can:
			final_ans.append(r)
	count = 0
	for i in final_ans:
		count += max(i) - min(i) + 1
	print(count)


for ad in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	low = 0
	up = 0
	t = 0
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if t == 0:
			if l <= x <= r:
				t = 1
				(low, up) = (l, r)
		elif low <= l <= up or low <= r <= up or l <= low <= up <= r:
			low = min(low, l)
			up = max(r, up)
	print(up - low + 1)


t = int(input())
while t > 0:
	t -= 1
	l = [int(x) for x in input().split()]
	(n, x, m) = (l[0], l[1], l[2])
	rng = [x, x + 1]
	for i in range(m):
		nr = [int(x) for x in input().split()]
		nr[1] += 1
		if nr[0] <= rng[0] and nr[1] >= rng[1]:
			rng = nr.copy()
		elif nr[1] > rng[0] and nr[1] <= rng[1]:
			rng[0] = min(nr[0], rng[0])
		elif nr[0] >= rng[0] and nr[0] < rng[1]:
			rng[1] = max(nr[1], rng[1])
	print(rng[1] - rng[0])


t = int(input())
while t > 0:
	(n, x, m) = map(int, input().split())
	seg = [(x, x)]
	for i in range(m):
		(a, b) = map(int, input().split())
		for s in seg:
			if s[0] < a and s[1] < a or (s[0] > b and s[1] > b):
				continue
			seg.append((a, b))
			break
	q = []
	for s in seg:
		q.append(s[0])
		q.append(s[1])
	q.sort()
	print(q[-1] - q[0] + 1)
	t -= 1


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


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


t = int(input())
for u in range(t):
	(n, k, m) = map(int, input().split())
	(st, end) = (k, k)
	for i in range(m):
		(x, y) = map(int, input().split())
		if st >= x and st <= y or (end >= x and end <= y):
			st = min(st, x)
			end = max(end, y)
	print(end - st + 1)


for _ in range(int(input())):
	c = 1
	(n, x, m) = map(int, input().split())
	s1 = x - 1
	e1 = x - 1
	for i in range(m):
		(l, r) = map(int, input().split())
		if l - 1 <= s1 <= r - 1:
			s1 = l - 1
		if l - 1 <= e1 <= r - 1:
			e1 = r - 1
	print(e1 - s1 + 1)


def solve(a, x):
	ll = x
	rr = x
	for [l, r] in a:
		if l <= rr:
			rr = max(rr, r)
		if r >= ll:
			ll = min(ll, l)
	return rr - ll + 1
t = int(input())
for i_t in range(t):
	[n, x, m] = list(map(int, input().split(' ')))
	a = [None] * m
	for i_m in range(m):
		r = list(map(int, input().split(' ')))
		a[i_m] = r
	print(solve(a, x))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, x, m) = li()
	l = []
	for i in range(m):
		l.append(li())
	tot = 1
	curr = [x, x]
	for i in range(m):
		if l[i][0] <= curr[0] <= l[i][1] or l[i][0] <= curr[1] <= l[i][1]:
			curr[0] = min(curr[0], l[i][0])
			curr[1] = max(curr[1], l[i][1])
	print(curr[1] - curr[0] + 1)


I = lambda : map(int, input().split())
(t,) = I()
for _ in [0] * t:
	(n, x, m) = I()
	a = b = x
	for i in [0] * m:
		(l, r) = I()
		if l <= b <= r or l <= a <= r:
			a = min(a, l)
			b = max(b, r)
	print(b - a + 1)


t = int(input())
for q in range(t):
	g = input().split()
	n = int(g[0])
	x = int(g[1])
	m = int(g[2])
	d = []
	l = x
	r = x
	for i in range(m):
		d.append(input().split())
	for i in range(m):
		(d[i][0], d[i][1]) = (int(d[i][0]), int(d[i][1]))
	for i in range(m):
		if max(l, d[i][0]) <= min(r, d[i][1]):
			l = min(l, d[i][0])
			r = max(r, d[i][1])
	print(r - l + 1)


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


import sys, heapq
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, x, m) = map(int, input().split())
	(mi, ma) = (x, x)
	for i in range(m):
		(le, ri) = map(int, input().split())
		if ri >= mi and le <= ma:
			mi = min(mi, le)
			ma = max(ma, ri)
	print(ma - mi + 1)


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


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	(n, x, m) = mapin()
	x = x
	y = x
	for i in range(m):
		(l, r) = mapin()
		if max(l, x) <= min(r, y):
			x = min(l, x)
			y = max(r, y)
	print(y - x + 1)


def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	n = l[0]
	x = l[1]
	m = l[2]
	lp = x
	rp = x
	for i in range(m):
		l = inlt()
		if lp >= l[0] and lp <= l[1]:
			lp = l[0]
		if rp <= l[1] and rp >= l[0]:
			rp = l[1]
	print(rp - lp + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	maxx = -1
	minn = n + 1
	contained = False
	for i in range(m):
		(l, r) = map(int, input().split())
		if contained:
			if l <= minn and r >= minn:
				minn = min(l, minn)
				maxx = max(r, maxx)
			if l <= maxx and r >= maxx:
				minn = min(l, minn)
				maxx = max(r, maxx)
		elif l <= x and r >= x:
			contained = True
			minn = l
			maxx = r
	if contained == True:
		print(maxx - minn + 1)
	else:
		print(1)


for _ in range(int(input())):
	(n, k, m) = map(int, input().split())
	(mn, mx) = (-1, -1)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= k <= r and mn == -1 and (mx == -1):
			mn = l
			mx = r
		elif r < mn or l > mx:
			continue
		else:
			mn = min(mn, l)
			mx = max(mx, r)
	print(mx - mn + 1)


from collections import deque

def overlap(a, b):
	if b[0] < a[0]:
		(a, b) = (b, a)
	return b[0] <= a[1]
t = int(input())
for _ in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	main = []
	intervals = []
	for _ in range(m):
		interval = [int(x) for x in input().split()]
		intervals.append(interval)
		if main and overlap(main, interval):
			main = [min(main[0], interval[0]), max(main[1], interval[1])]
		if interval[0] <= x <= interval[1] and (not main):
			main = interval
	if not main:
		print(1)
	else:
		print(main[1] - main[0] + 1)


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


import math
t = int(input())
for j in range(t):
	(n, x, m) = map(int, input().strip().split(' '))
	x1 = 10 ** 10
	x2 = 0
	f = 0
	for i in range(m):
		(l, r) = map(int, input().strip().split(' '))
		if f == 0 and x >= l and (x <= r):
			x1 = l
			x2 = r
			f = 1
		elif x1 >= l and x1 <= r or (x2 >= l and x2 <= r):
			x1 = min(l, x1)
			x2 = max(r, x2)
	print(max(x2 - x1 + 1, 1))


for case in range(int(input())):
	flag = True
	(n, x, m) = [int(x) for x in input().split()]
	L = 99999999999
	R = 0
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		if flag and l <= x <= r:
			L = min(l, L)
			R = max(r, R)
			flag = False
		elif l <= R and r >= L:
			L = min(L, l)
			R = max(R, r)
	if flag:
		print(1)
	else:
		print(R - L + 1)


t = input()
for _ in range(int(t)):
	(n, x, m) = map(int, input().split())
	left = x
	right = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if l > right or r < left:
			continue
		else:
			left = min(l, left)
			right = max(r, right)
	print(right - left + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	i = 0
	ln = []
	while i < m:
		(l, r) = map(int, input().split())
		ln.append([l, r])
		i += 1
	a1 = x
	a2 = x
	for el in ln:
		if el[0] <= a2 and a1 <= el[1]:
			if el[0] < a1:
				a1 = el[0]
			if el[1] > a2:
				a2 = el[1]
	print(a2 - a1 + 1)


for xyz in range(0, int(input())):
	(n, x, m) = map(int, input().split())
	r = []
	for i in range(0, m):
		r.append(list(map(int, input().split())))
	p = -1
	for i in range(0, m):
		if x >= r[i][0] and x <= r[i][1]:
			p = i
			break
	if p == -1:
		print(1)
	else:
		cr = [r[p][0], r[p][1]]
		for i in range(p, m):
			if r[i][0] <= cr[1] and r[i][1] >= cr[0]:
				cr[1] = max(cr[1], r[i][1])
				cr[0] = min(cr[0], r[i][0])
		print(cr[1] - cr[0] + 1)


import sys
import math
from collections import defaultdict

def solve(test):
	(n, x, m) = map(int, input().split())
	rec = [x, x]
	for i in range(m):
		(l, r) = map(int, input().split())
		if rec[1] >= l and rec[0] <= r:
			rec[0] = min(rec[0], l)
			rec[1] = max(rec[1], r)
	ans = rec[1] - rec[0] + 1
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


ip = lambda : list(map(int, input().split()))
for _ in '0' * int(input()):
	(n, x, m) = ip()
	(a, b) = (x, x)
	for i in '0' * m:
		(l, r) = ip()
		if b >= l and a <= r:
			a = min(l, a)
			b = max(b, r)
	print(b - a + 1)


for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	index = []
	temp = 0
	low = 0
	high = 0
	check = 0
	index = [x, x]
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if l >= index[0] and l <= index[1] and (r >= index[1]):
			index[1] = r
		if r >= index[0] and r <= index[1] and (l <= index[0]):
			index[0] = l
		if l <= index[0] and r >= index[1]:
			index[0] = l
			index[1] = r
	print(index[1] - index[0] + 1)


t = int(input())
for i in range(t):
	k = 0
	flag = False
	nxm = input().split()
	n = int(nxm[0])
	x = int(nxm[1])
	m = int(nxm[2])
	odz = [x, x]
	for j in range(m):
		lr = input().split()
		l = int(lr[0])
		r = int(lr[1])
		if l < odz[0] and r < odz[0] or l > odz[1]:
			continue
		if l < odz[0]:
			odz[0] = l
		if r > odz[1]:
			odz[1] = r
	k = odz[1] - odz[0] + 1
	print(k)


for _ in range(int(input())):
	(n, k, m) = list(map(int, input().split()))
	ma = 1
	mi = n
	for _ in range(m):
		(a, b) = list(map(int, input().split()))
		if a <= k and b >= k:
			mi = min(mi, a)
			ma = max(ma, b)
		elif b >= mi and a <= mi:
			mi = a
		elif b >= ma and a <= ma:
			ma = b
	if ma < mi:
		print(1)
	else:
		print(ma - mi + 1)


t = int(input())
c = []
for i in range(t):
	(n, x, m) = input().split()
	(n, x, m) = (int(n), int(x), int(m))
	x -= 1
	low = x
	high = x
	for j in range(m):
		(l, r) = input().split()
		(l, r) = (int(l) - 1, int(r) - 1)
		if low <= l and high >= r or (low <= l and high >= l) or (low >= l and low <= r):
			if low > l:
				low = l
			if high < r:
				high = r
	c.append(high - low + 1)
for k in c:
	print(k)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	ranl = 0
	ranr = 0
	for _ in range(m):
		(l, r) = map(int, input().split())
		if ranl == 0 and ranr == 0:
			if l <= x and x <= r:
				ranl = l
				ranr = r
			else:
				continue
		elif r < ranl or l > ranr:
			continue
		elif l <= ranl and r >= ranr:
			ranl = l
			ranr = r
		elif r >= ranr and l <= ranr:
			ranr = r
		elif l <= ranl and r <= ranr:
			ranl = l
	print(ranr - ranl + 1)


ans = []
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(p, q) = (x, x)
	ok = False
	for i in range(m):
		(a, b) = map(int, input().split())
		if p <= a <= q or p <= b <= q or a <= p <= b:
			p = min(a, p)
			q = max(b, q)
			ok = True
	ans.append(q - p + 1)
print('\n'.join(map(str, ans)))


def intersect(s1, s2):
	return s2[0] <= s1[0] <= s2[1] or s2[0] <= s1[1] <= s2[1]

def solve():
	(n, x, m) = map(int, input().split())
	l = x
	r = x
	for i in range(m):
		(tl, tr) = map(int, input().split())
		if intersect((l, r), (tl, tr)):
			l = min(l, tl)
			r = max(r, tr)
	print(r - l + 1)
t = int(input())
while t:
	t -= 1
	solve()


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	(n, x, m) = int_input()
	lr = [x, x]
	for _ in range(m):
		(l, r) = int_input()
		if l <= lr[0] <= r or l <= lr[1] <= r:
			lr = [min(l, lr[0]), max(r, lr[1])]
	print(lr[1] - lr[0] + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	xl = x
	xr = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= xl <= r:
			xl = l
		if l <= xr <= r:
			xr = r
	print(xr - xl + 1)


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


t = int(input())
for _ in range(t):
	(n, k, m) = map(int, input().split())
	res = 0
	min_ = 10 ** 9
	max_ = -1
	for _ in range(m):
		(a, b) = map(int, input().split())
		if a <= k <= b:
			min_ = min(a, min_)
			max_ = max(b, max_)
		else:
			if min_ <= b:
				min_ = min(min_, a)
			if max_ >= a:
				max_ = max(max_, b)
	print(max_ - min_ + 1 if max_ != -1 else 1)


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


import sys

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

def arr():
	return list(map(int, input().split()))
input = sys.stdin.readline
from collections import defaultdict
import math
for _ in range(int(input())):
	(N, X, M) = map(int, input().split())
	t = 0
	start = X
	end = X
	Range = []
	for i in range(M):
		(L, R) = map(int, input().split())
		if start > R or end < L:
			continue
		else:
			L1 = []
			L1.append(L)
			L1.append(R)
			Range.append(L1)
			start = min(L, start)
			end = max(R, end)
	print(end - start + 1)


from sys import stdin, stdout
import sys

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
for _ in range(int(stdin.readline())):
	(n, x, m) = get_ints()
	(a, b) = (x, x)
	for i in range(m):
		(l, r) = get_ints()
		if r < a or l > b:
			pass
		else:
			a = min(a, l)
			b = max(b, r)
	print(b - a + 1)


def main(n, x, m, left, right):
	(l, r) = (n, 0)
	for i in range(len(left)):
		if x > right[i]:
			if left[i] <= l <= right[i]:
				l = left[i]
		elif x < left[i]:
			if left[i] <= r <= right[i]:
				r = right[i]
		else:
			(l, r) = (min(l, left[i]), max(r, right[i]))
	if r - l + 1 <= 0:
		return 1
	return r - l + 1
for _ in range(int(input())):
	(n, x, m) = [int(i) for i in input().split()]
	(left, right) = ([], [])
	for i in range(m):
		inp = input().split()
		left.append(int(inp[0]))
		right.append(int(inp[1]))
	print(main(n, x, m, left, right))


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for i in range(inin()):
	(n, x, m) = cin()
	mi = n
	ma = 1
	ans = 0
	f = 0
	for i in range(m):
		(l, r) = cin()
		if x <= r and x >= l and (f == 0):
			ans += r - l + 1
			f = 1
			mi = l
			ma = r
		elif l > ma:
			continue
		elif r < mi:
			continue
		elif l >= mi and r <= ma:
			continue
		else:
			t1 = mi
			t2 = ma
			mi = min(l, mi)
			ma = max(r, ma)
			ans += t1 - mi + (ma - t2)
	if ans == 0:
		ans = 1
	print(ans)


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	P = x
	Q = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if Q <= r:
			if Q > l:
				Q = l
		if P >= l:
			if P < r:
				P = r
	print(P - Q + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(rl, rh, f) = (0, 0, 0)
	for i in range(m):
		(l, h) = map(int, input().split())
		if (x >= l and x <= h) and f == 0:
			rl = l
			rh = h
			f = 1
		if l <= rl and h >= rl:
			rl = l
			if rh <= h:
				rh = h
		if l <= rh and h >= rh:
			rh = h
	print(rh - rl + 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 swap(n, x, m, a):
	ind = x
	indices = 0
	for k in range(m):
		i = a[k][0]
		j = a[k][1]
		if ind >= i and ind <= j:
			ini = i
			final = j
			indices = final - ini + 1
			final_index = k
			break
	if indices != 0:
		for l in range(final_index + 1, m):
			i = a[l][0]
			j = a[l][1]
			if i < ini:
				if j >= ini and j <= final:
					indices += ini - i
					ini = i
				elif j > final:
					indices = j - i + 1
					ini = i
					final = j
			elif i >= ini and i <= final and (j > final):
				indices += j - final
				final = j
	if indices == 0:
		return 1
	else:
		return indices
T = int(input())
for i in range(T):
	(n, x, m) = [int(i) for i in input().split()]
	arr = []
	for i in range(m):
		row = [int(i) for i in input().split()]
		arr.append(row)
	print(swap(n, x, m, arr))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(l, r) = (x, x)
	for y in range(m):
		(a, b) = map(int, input().split())
		if a <= l <= b or a <= r <= b:
			l = min(a, l)
			r = max(b, r)
	print(r - l + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	maxi = x
	mini = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if mini > b or maxi < a:
			continue
		mini = min(a, mini)
		maxi = max(b, maxi)
	print(maxi - mini + 1)


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, x, m) = R()
	y = x
	for _ in [0] * m:
		(l, r) = R()
		if y >= l and r >= x:
			x = min(x, l)
			y = max(y, r)
	print(y - x + 1)


t = int(input())
for ingles in range(t):
	X = input()
	X1 = X.split()
	n = int(X1[0])
	x = int(X1[1])
	m = int(X1[2])
	xmax = x
	xmin = x
	L = []
	M = []
	for i in range(m):
		cosa = input()
		cos = cosa.split()
		L.append(int(cos[0]))
		M.append(int(cos[1]))
	for i in range(m):
		if L[i] <= xmax <= M[i]:
			xmax = M[i]
		if L[i] <= xmin <= M[i]:
			xmin = L[i]
	print(xmax - xmin + 1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	(left, right) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if right < l:
			continue
		if r < left:
			continue
		if l < left:
			left = l
		if right < r:
			right = r
	print(right - left + 1)


from sys import stdin, stdout
import sys
from math import *
input = stdin.buffer.readline
for __ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = [[x, x]]
	rn = [x, x]
	for i in range(m):
		(l, r) = map(int, input().split())
		if rn[1] < l:
			continue
		elif rn[0] > r:
			continue
		a.append([l, r])
		rn[0] = min(l, rn[0])
		rn[1] = max(r, rn[1])
	print(rn[1] - rn[0] + 1)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
for _ in range(int(cin())):
	(n, x, m) = map(int, cin().split())
	a = [x, x]
	for _ in range(m):
		(l, r) = map(int, cin().split())
		if l <= a[0] <= r:
			a[0] = l
			a[1] = max(a[1], r)
		elif l <= a[1] <= r:
			a[0] = min(l, a[0])
			a[1] = r
	cout(str(a[-1] - a[-2] + 1) + '\n')


import sys
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	ans = set([x])
	(l, r) = (x, x)
	for i in range(m):
		(l1, r1) = map(int, input().split())
		if max(l, l1) <= min(r, r1):
			l = min(l1, l)
			r = max(r, r1)
	print(r - l + 1)


import sys
import math
input = sys.stdin.readline
import copy
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	ranges = {(x, x)}
	for _ in range(m):
		(s, e) = map(int, input().split())
		for r in copy.copy(ranges):
			if s > r[1]:
				continue
			if e < r[0]:
				continue
			ranges.add((s, e))
	ranges = list(ranges)
	ranges.sort()
	s = ranges[0][0]
	ans = 0
	for r in ranges:
		if r[1] < s:
			continue
		ans += max(r[1], s) - max(r[0], s) + 1
		s = max(r[1], s) + 1
	print(ans)


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


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


import heapq
from collections import *
import math

def solve():
	(n, x, m) = map(int, input().split())
	(maxi, mini) = (float('-inf'), float('inf'))
	(x1, x2) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		f = 0
		if x1 >= a and x1 <= b or (x2 >= a and x2 <= b):
			f = 1
			maxi = max(maxi, a, b)
			mini = min(mini, a, b)
		if f == 1:
			x1 = mini
			x2 = maxi
	if maxi - mini + 1 == float('-inf'):
		print(1)
		return
	print(maxi - mini + 1)
t = int(input())
for _ in range(t):
	solve()


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 9 + 7
for _ in range(I()):
	(n, x, m) = R()
	l = r = x
	ans = 1
	for _ in range(m):
		(a, b) = R()
		if a >= l and b <= r:
			continue
		elif a < l and b > r:
			l = a
			r = b
			ans = r - l + 1
		elif a < l and l <= b and (b <= r):
			l = a
			ans = r - l + 1
		elif l <= a and a <= r and (b > r):
			r = b
			ans = r - l + 1
	print(ans)


t = int(input())
for z in range(t):
	(n, x, m) = [int(i) for i in input().split()]
	l = r = x
	for i in range(m):
		(c, d) = [int(i) for i in input().split()]
		if c <= l and d >= r:
			l = c
			r = d
		if c > l and c <= r and (d > r):
			r = d
		if c < l and d < r and (d >= l):
			l = c
	print(r - l + 1)


t = int(input())
for i in range(t):
	(n, x, m) = input().split()
	x = int(x)
	m = int(m)
	l_final = None
	r_final = None
	for j in range(m):
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		if l_final is None and r_final is None:
			if x >= l and x <= r:
				l_final = l
				r_final = r
		else:
			if r >= r_final and l <= r_final:
				r_final = r
			if l <= l_final and r >= l_final:
				l_final = l
	if l_final is None and r_final is None:
		print(1)
	else:
		print(r_final - l_final + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	le = x
	ri = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= le <= b:
			le = a
		if a <= ri <= b:
			ri = b
	print(ri - le + 1)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	c = 0
	mi = x
	ma = x
	y = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if y == 0:
			if l <= x <= r and l != r:
				mi = l
				ma = r
				y = 1
			else:
				pass
		elif l <= mi and r >= ma:
			mi = l
			ma = r
		elif l <= ma and r >= ma:
			ma = r
		elif l <= mi and r >= mi:
			mi = l
		else:
			pass
	print(ma - mi + 1)


def main():
	(n, x, m) = 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)
t = int(input())
for i in range(t):
	main()


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


t = int(input())
while t > 0:
	inp = list(map(int, input().split()))
	n = inp[0]
	x = inp[1]
	m = inp[2]
	flag = 0
	left_ptr = x
	right_ptr = x
	for i in range(m):
		inp1 = list(map(int, input().split()))
		l = inp1[0]
		r = inp1[1]
		if flag == 0 and x >= l and (x <= r):
			left_ptr = l
			right_ptr = r
			flag = 1
		elif flag == 1:
			if r >= left_ptr and r <= right_ptr and (l <= left_ptr):
				left_ptr = l
			elif l >= left_ptr and r >= right_ptr and (l <= right_ptr):
				right_ptr = r
			elif left_ptr >= l and right_ptr <= r:
				left_ptr = l
				right_ptr = r
	print(right_ptr - left_ptr + 1)
	t -= 1


tc = int(input())
while tc > 0:
	(n, x, m) = map(int, input().split())
	lx = x
	rx = x
	while m > 0:
		(l, r) = map(int, input().split())
		if min(rx, r) - max(lx, l) >= 0:
			lx = min(lx, l)
			rx = max(rx, r)
		m -= 1
	print(rx - lx + 1)
	tc -= 1


N = int(input())
for _ in range(N):
	(n, x, m) = map(int, input().split())
	(ans_L, ans_R) = (x, x)
	for i in range(m):
		(L, R) = map(int, input().split())
		if R < ans_L or L > ans_R:
			continue
		(ans_L, ans_R) = (min(ans_L, L), max(ans_R, R))
	print(ans_R - ans_L + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(ul, ur) = (-1, -1)
	for __ in range(m):
		(l, r) = map(int, input().split())
		if ul == -1 and ur == -1:
			if x >= l and x <= r:
				(ul, ur) = (l, r)
		elif ul <= r and ur >= l:
			ul = min(ul, l)
			ur = max(ur, r)
	print(ur - ul + 1)


def program():
	(n, k, q) = map(int, input().split())
	start = k
	end = k
	for i in range(q):
		(a, b) = map(int, input().split())
		if b < start:
			continue
		if a > end:
			continue
		start = min(start, a)
		end = max(end, b)
	print(end - start + 1)
for i in range(int(input())):
	program()


t = int(input())
for q in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	right = x
	left = x
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		if l <= left and r >= right:
			left = l
			right = r
		elif l <= left and r <= right and (r >= left):
			left = l
		elif l >= left and r >= right and (l <= right):
			right = r
	print(right - left + 1)


testing_mode = True
import sys, traceback
test_data = ''
final_output = ''

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for x in range(multi)]
	else:
		next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input

def log(*args):
	if testing_mode:
		print(*args)

def out(output_line, output_format=0, newline=True):
	global final_output
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	if testing_mode:
		final_output += formatted_output + '\n' * newline
	else:
		print(formatted_output, end='\n' if newline else '')
test_inputs = ['\n3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']
test_outputs = ['\n6\n2\n3\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']

def solve():
	for z in range(input(1)[0]):
		(n, x, m) = input(1)
		vl = x
		vr = x
		for i in range(m):
			(l, r) = input(1)
			if r >= vl and l <= vr:
				vl = min(vl, l)
				vr = max(vr, r)
		s = vr - vl + 1
		out(s)
	return

def run_all(overwrite_testing=False):
	global testing_mode, final_output, test_data
	testing_mode = overwrite_testing and testing_mode
	if testing_mode:
		tests_failed = 0
		for (test_number, (test_in, test_out)) in enumerate(zip(test_inputs, test_outputs)):
			final_output = ''
			if test_in.lstrip()[:3] == '$$$':
				continue
			test_data = iter([i for i in test_in.split('\n') if i])
			print(f'Test Case #{test_number + 1}:')
			print('<' * 20)
			fail = False
			verdict = '\x1b[92m\x1b[1mPASS\x1b[0m'
			try:
				solve()
				final = final_output.rstrip('\n')
				raw_out = iter(map(str, final.split('\n'))) if final else iter(())
			except Exception:
				raw_out = ''
				fail = True
				print('\x1b[95m')
				traceback.print_exc()
				print('\x1b[0m')
			if raw_out:
				if test_out.lstrip()[:3] == '$$$':
					verdict = '\x1b[94m\x1b[1mSKIP\x1b[0m'
					print('\x1b[94m' + '\n'.join(list(raw_out)) + '\x1b[0m')
				else:
					for line_out in [i for i in test_out.split('\n') if i]:
						line_raw = next(raw_out, '% None %')
						if line_raw == line_out.strip():
							print(f'\x1b[92m{line_raw}\x1b[0m')
						else:
							print(f'\x1b[91m{line_raw}\x1b[0m')
							fail = True
					line_raw = next(raw_out, None)
					while line_raw:
						print(f'\x1b[91m{line_raw}\x1b[0m')
						line_raw = next(raw_out, None)
						fail = True
			print('>' * 20)
			if fail:
				verdict = '\x1b[91m\x1b[1mFAIL\x1b[0m'
				tests_failed += 1
			print(verdict + '\n')
		if tests_failed:
			print(f"\x1b[91m\x1b[1m{tests_failed} TEST{('S' if tests_failed > 1 else '')} FAILED!\x1b[0m")
		else:
			print(f'\x1b[92m\x1b[1mALL TESTS PASSED!\x1b[0m')
	else:
		test_data = False
		solve()
run_all(False)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	oper = [0 for q in range(m)]
	for j in range(m):
		oper[j] = list(map(int, input().split()))
	left_border = x
	right_border = x
	for s in oper:
		if s[0] < left_border <= s[1]:
			left_border = s[0]
		if s[0] <= right_border < s[1]:
			right_border = s[1]
	print(right_border - left_border + 1)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = b = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if l < a and r >= a:
			a = l
		if r > b and l <= b:
			b = r
	print(b - a + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	lst = []
	for i in range(m):
		tmp = list(map(int, input().split()))
		lst.append(tmp)
	while lst and (not lst[0][0] <= x <= lst[0][1]):
		lst.pop(0)
	if not lst:
		print(1)
	else:
		ans = [lst[0]]
		for i in range(1, len(lst)):
			if lst[i][0] < ans[-1][0] and ans[-1][1] < lst[i][1]:
				ans[-1] = lst[i]
			elif ans[-1][0] <= lst[i][1] <= ans[-1][1] and lst[i][0] < ans[-1][0]:
				ans[-1][0] = lst[i][0]
			elif ans[-1][0] <= lst[i][0] <= ans[-1][1] and lst[i][1] > ans[-1][1]:
				ans[-1][1] = lst[i][1]
		if ans:
			print(ans[-1][1] - ans[-1][0] + 1)
		else:
			print(1)


from collections import Counter as ctr
from collections import defaultdict as dd
from sys import stdin, stdout
for t in range(int(stdin.readline().strip())):
	(n, x, m) = map(int, stdin.readline().strip().split())
	l = x
	r = x
	for i in range(m):
		(li, ri) = map(int, stdin.readline().strip().split())
		if li <= l and ri >= l:
			l = li
		if ri >= r and li <= r:
			r = ri
	stdout.write(str(r - l + 1) + '\n')


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


def ab():
	(n, x, m) = map(int, input().split())
	l = x
	r = x
	ans = 1
	while m > 0:
		m = m - 1
		(p, q) = map(int, input().split())
		if p < l and q >= r or (p < l and q >= l and (q <= r)):
			ans = ans + l - p
			l = p
			if q > r:
				ans = ans + q - r
				r = q
		elif p > l and p <= r and (q > r):
			ans = ans + q - r
			r = q
		elif p == l and q > r:
			ans = ans + q - r
			r = q
	print(ans)
for i in range(0, int(input())):
	ab()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	L = x
	R = x
	a = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= L and r >= R:
			L = min(l, L)
			R = max(R, r)
			a = 1
		elif l >= L and l <= R:
			L = min(l, L)
			R = max(R, r)
			a = 1
		elif r >= L and r <= R:
			L = min(l, L)
			R = max(R, r)
			a = 1
	if L <= R and a:
		print(R - L + 1)
	else:
		print(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
		elif intersect(left, right, currleft, currright):
			currleft = min(left, currleft)
			currright = max(right, currright)
	print(currright - currleft + 1)


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


testCases = int(input())
for i in range(testCases):
	(n, x, m) = list(map(int, input().split()))
	(l, r) = list(map(int, input().split()))
	if l > x or x > r:
		(l, r) = (x, x)
	for i in range(m - 1):
		(l1, r1) = list(map(int, input().split()))
		if l1 <= l <= r1 <= r:
			l = l1
		elif l <= l1 <= r <= r1:
			r = r1
		elif l1 <= l <= r <= r1:
			(l, r) = (l1, r1)
	print(r - l + 1)


for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	(l, h) = (x, x)
	for j in range(m):
		(a, b) = list(map(int, input().split()))
		if b < l or a > h:
			continue
		else:
			l = min(l, a)
			h = max(h, b)
	print(h - l + 1)


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


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


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, x, m) = invr()
	start = x
	end = x
	for _ in range(m):
		(l, r) = invr()
		if l <= start <= r or l <= end <= r or (start <= l and end >= r):
			start = min(start, l)
			end = max(end, r)
	print(end - start + 1)


for testcase in range(int(input())):
	(length, start, operations) = map(int, input().split())
	bounds = []
	for i in range(operations):
		bounds.append(tuple(map(int, input().split())))
	low = start
	up = start
	for b in bounds:
		(l, u) = b
		if l <= low and u >= up:
			low = l
			up = u
		elif l < low and low <= u <= up:
			low = l
		elif u > up and low <= l <= up:
			up = u
	print(up - low + 1)


import math
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	ans = []
	cnt = 0
	f = False
	le = 10 ** 9 + 1
	le1 = -1
	for j in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r:
			f = True
			le = min(le, l)
			le1 = max(le1, r)
		elif le1 < l or r < le:
			continue
		else:
			le = min(le, l)
			le1 = max(le1, r)
	print(max(1, le1 - le + 1))


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	(xmin, xmax) = (x, x)
	for i in range(m):
		(l, u) = map(int, input().split())
		if l <= xmin <= u:
			xmin = l
		if l <= xmax <= u:
			xmax = u
	print(xmax - xmin + 1)


for _ in range(int(input())):
	(n, k, m) = list(map(int, input().split()))
	mn = mx = k
	for i in range(m):
		(a, b) = list(map(int, input().split()))
		if a <= mn and b >= mn or (a <= mx and b >= mx):
			mn = min(a, mn)
			mx = max(b, mx)
	print(mx - mn + 1)


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


def f(r1, r2):
	if r1[0] <= r2[0] and r1[1] >= r2[0]:
		return True
	elif r1[0] > r2[0] and r2[1] >= r1[0]:
		return True
	return False
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	ansrange = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		res = f((a, b), ansrange)
		if res:
			ansrange = (min(a, ansrange[0]), max(ansrange[1], b))
	print(ansrange[1] - ansrange[0] + 1)


def combine(a, b):
	temp = [a, b]
	temp.sort()
	mn = temp[0][0]
	if temp[1][0] <= temp[0][1]:
		mx = max(temp[0][1], temp[1][1])
		return [mn, mx]
	return -1
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	cnt = 0
	ls = []
	ran = [-1, -1]
	for ms in range(m):
		(l, r) = map(int, input().split())
		if ran[0] == -1:
			if l <= x <= r:
				ran = [l, r]
		else:
			ans = combine(ran, [l, r])
			if ans != -1:
				ran = ans
	if ran[0] == -1:
		print(1)
	else:
		print(ran[1] - ran[0] + 1)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	for _ in range(int(input())):
		(n, k, m) = map(int, input().split(' '))
		intervals = []
		for y in range(m):
			intervals.append(list(map(int, input().split(' '))))
		start = k
		end = k
		realans = 0
		for x in range(len(intervals)):
			if max(start, intervals[x][0]) <= min(end, intervals[x][1]):
				end = max(intervals[x][1], end)
				start = min(intervals[x][0], start)
		print(end - start + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t != 0:
	t -= 1
	(n, x, m) = [int(x) for x in input().split()]
	flag = 0
	ans = []
	for i in range(m):
		(li, ri) = [int(x) for x in input().split()]
		if x >= li and x <= ri and (len(ans) == 0):
			ans.append(li)
			ans.append(ri)
		if len(ans) == 2:
			if li >= ans[0] and li <= ans[1] or (ri >= ans[0] and ri <= ans[1]) or (li <= ans[0] and ri >= ans[1]):
				ans[0] = min(li, ans[0], ri)
				ans[1] = max(li, ans[1], ri)
	if len(ans) > 0:
		print(max(ans) - min(ans) + 1)
	else:
		print(1)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			(n, x, m) = invr()
			(mn, mx) = (x, x)
			f = False
			for _ in range(m):
				(a, b) = invr()
				if f:
					if a <= mn <= b or a <= mx <= b:
						mn = min(mn, a)
						mx = max(mx, b)
				elif a <= x <= b:
					mn = a
					mx = b
					f = True
			print(mx - mn + 1)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	inp = list(map(int, input().split()))
	n = inp[0]
	x = inp[1]
	m = inp[2]
	x1 = x
	x2 = x
	for j in range(m):
		inp2 = list(map(int, input().split()))
		l = inp2[0]
		r = inp2[1]
		if l <= x1 <= r or l <= x2 <= r or (x1 < l and x2 > r):
			x1 = min(x1, l)
			x2 = max(x2, r)
	print(x2 - x1 + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	l = 0
	r = 0
	cnt = 0
	lock = 0
	for _ in range(m):
		(a, b) = map(int, input().split())
		if lock == 0:
			if x >= a and x <= b:
				cnt = b - a + 1
				l = a
				r = b
				lock = 1
				prev_a = a
				prev_b = b
		elif (prev_a >= a and prev_a <= b) and (prev_b >= a and prev_b <= b):
			if l - a >= 0:
				cnt += l - a
				if a < l:
					l = a
			if b - r >= 0:
				cnt += b - r
				if b > r:
					r = b
		elif prev_a >= a and prev_a <= b:
			if l - a >= 0:
				cnt += l - a
				l = a
		elif prev_b >= a and prev_b <= b:
			if b - r >= 0:
				cnt += b - r
				r = b
		elif r >= a and r <= b:
			if b - r >= 0:
				cnt += b - r
				r = b
		elif l >= a and l <= b:
			if l - a >= 0:
				cnt += l - a
				l = a
		else:
			continue
		prev_a = a
		prev_b = b
	if cnt == 0:
		print(1)
	else:
		print(cnt)


from sys import stdin, stdout
for cases in range(int(stdin.readline())):
	(n, x, m) = map(int, stdin.readline().split())
	l = [0] * m
	r = [0] * m
	l1 = x
	r1 = x
	for i in range(m):
		(l[i], r[i]) = map(int, stdin.readline().split())
		if l1 >= l[i] and r1 <= r[i]:
			l1 = l[i]
			r1 = r[i]
		elif l1 == r[i] or r1 == l[i]:
			l1 = min(l1, l[i])
			r1 = max(r1, r[i])
		elif l[i] >= l1 and l[i] <= r1 or (r[i] >= l1 and r[i] <= r1):
			l1 = min(l1, l[i])
			r1 = max(r1, r[i])
	print(r1 - l1 + 1)


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


import math
t = int(input())
for cnt in range(t):
	(n, x, m) = map(int, input().split())
	l = list()
	r = list()
	range_min = -1
	range_max = -1
	flag = 0
	for i in range(m):
		(c, d) = map(int, input().split())
		l.append(c)
		r.append(d)
		if c <= x <= d and flag == 0:
			if range_min == -1:
				range_min = c
			elif range_min > c:
				range_min = c
			if range_max == -1:
				range_max = d
			elif range_max < d:
				range_max = d
			flag = 1
		elif c <= range_min <= d or (c <= range_max <= d and flag != 0):
			if range_min > c:
				range_min = c
			if range_max < d:
				range_max = d
	print(range_max - range_min + 1)


from math import *
from random import *

def intrsct(a1, a2):
	if a1[0] >= a2[0] and a1[0] <= a2[1] or (a1[1] >= a2[0] and a1[1] <= a2[1]) or (a2[0] >= a1[0] and a2[0] <= a1[1]) or (a2[1] >= a1[0] and a2[1] <= a1[1]):
		return True
	return False
for t in range(int(input())):
	(n, x, m) = map(int, input().split())
	prev = [(x, x)]
	for i in range(m):
		(l, r) = map(int, input().split())
		for pr in prev:
			if intrsct(pr, (l, r)):
				prev.append((l, r))
				break
	prev.sort()
	pos = prev[0]
	otv = pos[1] - pos[0] + 1
	for i in prev:
		if i[1] > pos[1]:
			otv += i[1] - i[0] + 1 - max(0, pos[1] - i[0] + 1)
			pos = i
	print(otv)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, x, m) = map(int, input().split())
	v = []
	for i in range(m):
		v.append(list(map(int, input().split())))
	start = x
	end = x
	for j in range(m):
		if max(start, v[j][0]) <= min(end, v[j][1]):
			start = min(start, v[j][0])
			end = max(end, v[j][1])
	print(end - start + 1)


def solve(case):
	(n, x, m) = map(int, input().split())
	l1 = x
	m1 = x
	for i in range(m):
		(l, m) = map(int, input().split())
		if l <= l1 and m >= l1:
			l1 = l
			if m > m1:
				m1 = m
		elif l <= m1 and m >= m1:
			m1 = m
	print(m1 - l1 + 1)
for _ in range(int(input())):
	solve(1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	xx = [x, x]
	ans = 1
	for f in range(m):
		(p, q) = map(int, input().split())
		if p <= xx[0] <= q or p <= xx[1] <= q:
			xx[0] = min(p, xx[0])
			xx[1] = max(q, xx[1])
	print(xx[1] - xx[0] + 1)


for _ in range(int(input())):
	(n, m, x) = [int(i) for i in input().split()]
	(left, right) = (m, m)
	for j in range(x):
		(l, r) = [int(k) for k in input().split()]
		if right >= l and left <= r:
			left = min(l, left)
			right = max(right, r)
	print(right - left + 1)


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


import sys
from collections import Counter

def read_ints():
	return [int(i) for i in input().strip().split()]

def solve():
	pass

def main():
	tc = int(input())
	for _ in range(tc):
		(n, x, m) = read_ints()
		(mn, mx) = (x, x)
		for _ in range(m):
			(left, right) = read_ints()
			if right < mn or left > mx:
				pass
			else:
				mn = min(mn, left)
				mx = max(mx, right)
		print(mx - mn + 1)
main()


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	ans = [None for i in range(t)]
	for i in range(t):
		L = []
		R = []
		k = 1
		(n, x, m) = map(int, stdin.readline().split())
		X = []
		X.append(x)
		for j in range(m):
			(l, r) = map(int, stdin.readline().split())
			if l <= max(X) and min(X) <= r:
				L.append(l)
				R.append(r)
				X.append(l)
				X.append(r)
		if len(L) and len(R):
			k += max(R) - min(L)
		ans[i] = k
	for i in range(t):
		print(ans[i])
main()


t = int(input())

def solve(n, x, m, ops, coords):
	coords = sorted(set(coords + [0] + [x] + [x + 1] + [n]))
	compress = {v: i for (i, v) in enumerate(coords)}
	decompress = {i: v for (i, v) in enumerate(coords)}
	intervals = [0] * (len(coords) - 1)
	intervals[compress[x]] = 1
	for (l, r) in ops:
		has1 = False
		for i in range(len(coords) - 1):
			if compress[l] <= i and compress[r + 1] >= i + 1:
				if intervals[i] == 1:
					has1 = True
					break
		if has1:
			for i in range(len(coords) - 1):
				if compress[l] <= i and compress[r + 1] >= i + 1:
					intervals[i] = 1
	cnt = 0
	for i in range(len(coords) - 1):
		if intervals[i]:
			cnt += decompress[i + 1] - decompress[i]
	return cnt
for _ in range(t):
	(n, x, m) = map(int, input().split())
	x -= 1
	operations = []
	points = []
	for _ in range(m):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		points.append(l)
		points.append(r + 1)
		operations.append((l, r))
	print(solve(n, x, m, operations, points))


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, x, m) = MI()
		lr = LLI(m)
		(L, R) = (x, x)
		for (l, r) in lr:
			if max(L, l) > min(R, r):
				continue
			L = min(L, l)
			R = max(R, r)
		print(R - L + 1)
main()


def intersects1(l, r, interval):
	(x, y) = interval
	low = max(l, x)
	high = min(r, y)
	return low <= high

def intersects2(l, r, intervals):
	for interval in intervals:
		if intersects1(l, r, interval):
			return True
	return False

def count(intervals):
	changes = []
	for (a, b) in intervals:
		changes += [(a, 1)]
		changes += [(b + 1, -1)]
	changes = sorted(changes)
	num_intervals = 0
	last_pos = None
	ret = 0
	for (pos, delta) in changes:
		if num_intervals > 0:
			if last_pos == pos:
				continue
			ret += pos - last_pos
		num_intervals += 1
		last_pos = pos
	return ret

def ans(n, x, lr):
	possible = [(x, x)]
	for (l, r) in lr:
		if intersects2(l, r, possible):
			possible += [(l, r)]
	return count(possible)
T = int(input())
for t in range(T):
	(n, x, m) = input().split(' ')
	n = int(n)
	x = int(x)
	m = int(m)
	lr = []
	for _ in range(m):
		(l, r) = input().split(' ')
		l = int(l)
		r = int(r)
		lr += [(l, r)]
	print(ans(n, x, lr))


for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	l = [list(map(int, input().split())) for __ in range(m)]
	lmi = x
	rma = x
	for i in range(m):
		if (l[i][0] <= lmi) & (l[i][1] <= rma) & (lmi <= l[i][1]):
			lmi = l[i][0]
		if (l[i][1] >= rma) & (l[i][0] >= lmi) & (rma >= l[i][0]):
			rma = l[i][1]
		if (l[i][0] <= lmi) & (l[i][1] >= rma):
			lmi = l[i][0]
			rma = l[i][1]
	print(rma - lmi + 1)


t = int(input())
for i in range(t):
	(n, k, m) = input().split()
	n = int(n)
	k = int(k)
	m = int(m)
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	result = 1
	if a <= k <= b:
		result = b - a + 1
	for j in range(m - 1):
		(c, d) = input().split()
		c = int(c)
		d = int(d)
		if result == 1:
			if c <= k <= d:
				result = d - c + 1
				a = c
				b = d
		elif not (b < c or d < a):
			a = min(a, c)
			b = max(b, d)
			result = b - a + 1
	print(result)


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	(n, x, m) = mi()
	(l, r) = ([0] * m, [0] * m)
	(cx, cy) = (x, x)
	for i in range(m):
		(l[i], r[i]) = mi()
		if cy < l[i] or cx > r[i]:
			continue
		cx = min(cx, l[i])
		cy = max(cy, r[i])
	print(cy - cx + 1)


for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	li = x
	ri = x
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if r >= ri and l <= ri:
			ri = r
		if l <= li and r >= li:
			li = l
	print(ri - li + 1)


for t in range(int(input())):
	(n, x, m) = map(int, input().split())
	X = []
	flag = True
	for i in range(m):
		(a, b) = map(int, input().split())
		X.append([a, b])
		if flag and a <= x <= b:
			index = i
			flag = False
	if flag:
		print(1)
	else:
		start = X[index]
		for i in range(index + 1, m):
			second = X[i]
			first = start[:]
			if second[0] < first[0]:
				(first, second) = (second[:], first[:])
			if first[1] >= second[0]:
				x = min(first[0], second[0])
				y = max(first[1], second[1])
				start = [x, y]
		print(start[1] - start[0] + 1)


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


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	ops = [tuple(map(int, input().split())) for _ in range(m)]
	(xmin, xmax) = (x, x)
	for (l, r) in ops:
		if l <= xmin <= r or l <= xmax <= r:
			xmin = min(xmin, l)
			xmax = max(xmax, r)
	print(xmax - xmin + 1)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	ans = 0
	la = []
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= x <= b and la == []:
			la.append([a, b])
		elif la != []:
			(c, d) = la[0]
			if c == a and d == b:
				pass
			elif a <= c <= b and a <= d <= b:
				la.pop()
				la.append((a, b))
			elif c <= a <= d and c <= b <= d:
				la.pop()
				la.append((c, d))
			elif c <= a <= d:
				la.pop()
				la.append((c, b))
			elif a <= c <= b:
				la.pop()
				la.append((a, d))
	if la != []:
		(a, b) = la[0]
		print(b - a + 1)
	else:
		print(1)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, x, m) = input_split()
	x -= 1
	ls = []
	rs = []
	for _ in range(m):
		(li, ri) = input_split()
		ls.append(li - 1)
		rs.append(ri - 1)
	(left, right) = (x, x)
	for i in range(m):
		if left > rs[i] or right < ls[i]:
			pass
		else:
			left = min(left, ls[i])
			right = max(right, rs[i])
	ans = right - left + 1
	answers.append(ans)
print(*answers, sep='\n')


import math
for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	lWas = x
	rWas = x
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if l < lWas and r >= lWas:
			lWas = min(l, lWas)
		if r > rWas and l <= rWas:
			rWas = max(r, rWas)
	print(rWas - lWas + 1)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	cl = x
	cr = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if cr < l or r < cl:
			continue
		cl = min(cl, l)
		cr = max(cr, r)
	print(cr - cl + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = list(map(int, input().split()))
	L = []
	for i in range(m):
		L.append(list(map(int, input().split())))
	i = x
	j = x
	for q in range(m):
		l = L[q][0]
		r = L[q][1]
		if l <= i and r >= i and (r <= j):
			i = l
		elif l <= i and r >= j:
			i = l
			j = r
		elif l >= i and l <= j and (r >= j):
			j = r
	print(j - i + 1)


from sys import stdin
t = int(input())
for _ in range(t):
	(n, xx, m) = [int(x) for x in stdin.readline().split()]
	highest = lowest = xx
	for _ in range(m):
		(a, b) = [int(x) for x in stdin.readline().split()]
		if a < lowest and b >= lowest:
			lowest = a
		if b > highest and a <= highest:
			highest = b
	ans = highest - lowest + 1
	print(ans)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	mi = ma = x
	for i in range(m):
		(f, s) = map(int, input().split())
		if f <= ma and s >= mi:
			mi = min(mi, f)
			ma = max(ma, s)
	print(ma - mi + 1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(n, x, m, LR):
	(ans_l, ans_r) = (x, x)
	for (l, r) in LR:
		if r < ans_l or l > ans_r:
			continue
		ans_l = min(ans_l, l)
		ans_r = max(ans_r, r)
	return ans_r - ans_l + 1

def main():
	t = int(input())
	for _ in range(t):
		(n, x, m) = map(int, input().split())
		LR = [tuple(map(int, input().split())) for _ in range(m)]
		ans = solve(n, x, m, LR)
		sys.stdout.write(str(ans) + '\n')
main()


T = int(input())
for isc in range(T):
	(n, x, m) = map(int, input().split())
	c = False
	(r1, r2) = (-1, -1)
	for i in range(m):
		(t1, t2) = map(int, input().split())
		if c:
			if not (t2 < r1 or t1 > r2):
				r1 = min(r1, t1)
				r2 = max(r2, t2)
		elif t1 <= x and x <= t2:
			(r1, r2, c) = (t1, t2, True)
	print(r2 - r1 + 1)


t = int(input())
for a in range(t):
	(n, x, m) = input().split()
	n = int(n)
	x = int(x)
	m = int(m)
	ll = 0
	rr = 0
	for q in range(m):
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		if l <= x and x <= r:
			ll = l
			rr = r
			x = 0
			continue
		if (ll <= l and l <= rr) and (ll <= r and r <= rr):
			continue
		if l < ll and rr < r:
			ll = l
			rr = r
		if l < ll and ll <= r:
			ll = l
		elif l <= rr and rr < r:
			rr = r
	d = rr - ll + 1
	print(d)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	(ul, ur) = (0, 0)
	for _ in range(m):
		(l, r) = map(int, input().split())
		if ul == 0:
			if l <= x <= r:
				(ul, ur) = (l, r)
		elif ul <= l <= ur or ul <= r <= ur or l <= ul <= r:
			(ul, ur) = (min(ul, l), max(ur, r))
	print(ur - ul + 1)


def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
Testcase = inin()
for _ in range(Testcase):
	(n, x, m) = inar()
	(p, q) = (x, x)
	for i in range(m):
		(l, r) = inar()
		if l < p and q < r:
			p = l
			q = r
			continue
		if p <= l <= q and r > q:
			q = r
			continue
		if l < p and p <= r <= q:
			p = l
	print(q - p + 1)


t = int(input())
for i in range(t):
	(n, x, m) = [int(_) for _ in input().split(' ')]
	gl = n
	gr = 0
	x_open = False
	res = 1
	for ii in range(m):
		(l, r) = [int(_) for _ in input().split(' ')]
		if l <= x <= r and x_open is False:
			x_open = True
		if x_open:
			if gl <= l <= gr or gl <= r <= gr or (l <= gl and r >= gr):
				if l < gl:
					gl = l
				if r > gr:
					gr = r
	if gr >= gl:
		res += gr - gl
	print(res)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		(n, x, m) = map(int, inputi().split())
		mn = x
		mx = x
		for _ in range(m):
			(l, r) = map(int, inputi().split())
			if mn <= r and mx >= l:
				mn = min(l, mn)
				mx = max(r, mx)
		print(mx - mn + 1)
	t = int(inputi())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	left = x
	right = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if r < left or l > right:
			pass
		else:
			left = min(l, left)
			right = max(r, right)
	print(right - left + 1)


for t in range(int(input())):
	(a, n, x) = map(int, input().split())
	(p, q) = (n, n)
	for i in range(x):
		(l, r) = map(int, input().split())
		if r < p:
			continue
		if q < l:
			continue
		if l < p:
			p = l
		if q < r:
			q = r
	print(q - p + 1)


import sys
input = sys.stdin.readline
t = int(input())
for ti in range(1, t + 1):
	(n, x, m) = map(int, input().split())
	a = []
	cur_l = cur_r = x
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if not (l <= cur_l <= r or l <= cur_r <= r):
			continue
		if cur_l <= x <= cur_r and (l <= cur_l or cur_r <= r):
			cur_l = min(cur_l, l)
			cur_r = max(cur_r, r)
	print(cur_r - cur_l + 1)


tc = int(input().strip())
while tc:
	(n, x, m) = map(int, input().strip().split())
	(al, ar) = (x, x)
	while m:
		(l, r) = map(int, input().strip().split())
		if l > ar or r < al:
			pass
		else:
			al = min(l, al)
			ar = max(r, ar)
		m -= 1
	ans = ar - al + 1
	print(ans)
	tc -= 1


def fun():
	(n, x, m) = map(int, input().split())
	mini = x
	maxi = x
	for z in range(m):
		(l, r) = map(int, input().split())
		if mini <= r and mini >= l or (maxi <= r and maxi >= l):
			if mini > l:
				mini = l
			if maxi < r:
				maxi = r
	return maxi - mini + 1
for z in range(int(input())):
	print(fun())


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	(n, x, m) = map(int, ip().split())
	(lf, rt) = (-1, -1)
	for _ in range(m):
		(l, r) = map(int, ip().split())
		if lf == -1:
			if x >= l and x <= r:
				(lf, rt) = (l, r)
				continue
		else:
			if l > rt or r < lf:
				continue
			lf = min(l, lf)
			rt = max(rt, r)
	print(rt - lf + 1)


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	(n, x, m) = [int(x) for x in input().split()]
	left = x
	right = x
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		if r >= left and l <= left or (r >= right and l <= right):
			left = min(left, l)
			right = max(r, right)
	print(right - left + 1)
tt = int(input())
for test in range(tt):
	solve()


t = int(input())
for _ in range(t):
	(n, x, m) = list(map(int, input().split()))
	l1 = -1
	r1 = -1
	flag = 0
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if flag == 0:
			if l <= x and r >= x:
				if l1 == -1 and r1 == -1:
					l1 = l
					r1 = r
					flag = 1
		elif r < l1:
			pass
		elif l > r1:
			pass
		else:
			if l <= l1:
				l1 = l
			if r >= r1:
				r1 = r
	print(r1 - l1 + 1)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def merge(a, b, x, y):
	if b < x or a > y:
		return (a, b)
	return (min(a, x), max(b, y))
for _ in range(int(input())):
	(n, x, m) = ilele()
	(i, j) = (x, x)
	for __ in range(m):
		(x, y) = ilele()
		(i, j) = merge(i, j, x, y)
	print(j - i + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	arr = [[x, x]]
	for i in range(m):
		(l, r) = map(int, input().split())
		flag = False
		for j in range(len(arr)):
			if arr[j][0] > r or arr[j][1] < l:
				continue
			else:
				flag = True
		if flag:
			arr.append([l, r])
	arr.sort()
	ans = 0
	L = arr[0][0]
	R = arr[0][1]
	for i in range(1, len(arr)):
		if arr[i][0] <= R:
			R = max(R, arr[i][1])
		else:
			ans += R - L + 1
			L = arr[i][0]
			R = arr[i][1]
	ans += R - L + 1
	print(ans)


t = int(input())
for q in range(t):
	(n, x, m) = list(map(int, input().split(' ')))
	inicio = 0
	fim = 0
	flag = False
	for i in range(m):
		(l, r) = list(map(int, input().split(' ')))
		if flag == False:
			if l <= x and x <= r:
				inicio = l
				fim = r
				flag = True
		elif inicio >= l and inicio <= r or (fim >= l and fim <= r):
			if l < inicio:
				inicio = l
			if r > fim:
				fim = r
	print(fim - inicio + 1)


def help():
	(n, x, m) = map(int, input().split(' '))
	ranges = [[x, x]]
	for i in range(m):
		(a, b) = map(int, input().split(' '))
		for j in ranges:
			if j[0] <= a and j[1] >= b:
				break
			if j[0] >= a and j[1] <= b:
				j[0] = a
				j[1] = b
				break
			if j[1] >= b and j[1] >= a and (j[0] <= b) and (j[0] >= a):
				j[0] = min(j[0], a)
				j[1] = max(j[1], b)
				break
			if b >= j[0] and b >= j[1] and (a >= j[0]) and (a <= j[1]):
				j[0] = min(j[0], a)
				j[1] = max(j[1], b)
				break
	ans = 0
	for i in ranges:
		ans += i[1] - i[0] + 1
	print(ans)
for _ in range(int(input())):
	help()


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, x, m) = map(int, fastinput().split())
	(initiall, initialr) = (x, x)
	for _ in range(m):
		(l, r) = map(int, fastinput().split())
		if l <= initiall and r >= initialr:
			initiall = l
			initialr = r
		elif l <= initiall and r >= initiall:
			initiall = l
		elif l <= initialr and r >= initialr:
			initialr = r
		else:
			continue
	print(initialr - initiall + 1)


t = int(input())

def search(num1, num2, lst):
	for i in lst:
		if i > num1 or i < num2:
			return 1
	return 0
for _ in range(t):
	(n, x, m) = map(int, input().split())
	arr = [[x, x]]
	l = 1
	mlist = []
	for i in range(m):
		c = list(map(int, input().split()))
		mlist.append(c.copy())
	for i in range(m):
		(a, b) = mlist[i]
		j = 0
		while j < len(arr):
			if arr[j][0] >= a and arr[j][1] <= b:
				arr.append([a, b])
				del arr[j]
				break
			if arr[j][0] <= b and b <= arr[j][1]:
				if arr[j][0] > a:
					arr.append([a, arr[j][1]])
					del arr[j]
					break
			elif arr[j][1] >= a and a >= arr[j][0]:
				if arr[j][1] < b:
					arr.append([arr[j][0], b])
					del arr[j]
					break
			j += 1
	ct = 0
	for (a, b) in arr:
		ct += b - a + 1
	print(ct)


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def f(m, a, b):
	if m > b or 2 * m > a or m < 0:
		return 0
	ans = m
	a -= 2 * m
	b -= m
	if a > b:
		(a, b) = (b, a)
	ans += min(a, b // 2)
	a -= b // 2
	b %= 2
	ans += min(b, a // 2)
	return ans

def solve():
	for _ in range(ii()):
		(n, k, m) = mi()
		l = n
		r = 1
		f = 0
		for i in range(m):
			(x, y) = mi()
			if f == 0:
				if x <= k <= y:
					l = x
					r = y
					f = 1
			else:
				if x > r or y < l:
					continue
				l = min(x, l)
				r = max(y, r)
		if f == 0:
			print(1)
		else:
			print(r - l + 1)
solve()


import sys
import math
from collections import defaultdict as dft

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

def mp():
	return map(int, input().split())

def debug(name, val):
	print(name, ':', val)

def solve():
	(n, x, m) = mp()
	ans = 1
	ls = []
	for i in range(m):
		ls.append(ml())
	res = []
	for (a, b) in ls:
		if len(res) == 0:
			if a <= x <= b:
				ans = max(ans, b - a + 1)
				res = [a, b]
		else:
			if res[0] > b or res[1] < a:
				continue
			res = [min(res[0], a), max(res[1], b)]
			ans = max(ans, res[1] - res[0] + 1)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import math
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	f = 0
	low = x
	high = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if f == 0:
			if l <= x <= r:
				low = l
				high = r
				f = 1
		elif r < low or l > high:
			continue
		else:
			high = max(r, high)
			low = min(l, low)
	print(high - low + 1)


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


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(n, x, m) = map(int, input().split())
	LR = [list(map(int, input().split())) for _ in range(m)]
	Query.append((n, x, m, LR))
for (N, X, M, LR) in Query:
	P = [[X, X]]
	for (l, r) in LR:
		willapp = False
		PP = []
		for (pl, pr) in P:
			if pl <= r and l <= pr:
				willapp = True
				l = min(l, pl)
				r = max(r, pr)
			else:
				PP.append((pl, pr))
		if willapp:
			PP.append((l, r))
		P = PP
	ans = 0
	for (l, r) in P:
		ans += r - l + 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, x, m) = 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)


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


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


import math
from collections import defaultdict

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	(n, x, m) = rm()
	low = -1
	high = -1
	for i in range(m):
		(a, b) = rm()
		if low == -1:
			if x <= b and x >= a:
				low = a
				high = b
		else:
			if low <= b and low >= a:
				low = a
			if high <= b and high >= a:
				high = b
	print(high - low + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	z = []
	maxi = x
	maxf = x
	for __ in range(m):
		(a, b) = map(int, input().split())
		if a <= maxi <= b:
			maxi = a
			maxf = max(maxf, b)
		elif maxi <= a and maxf >= a and (maxf <= b):
			maxf = b
	print(maxf - maxi + 1)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, x, m) = list(map(int, stdin.readline().split()))
	res_l = res_r = x
	for _ in range(m):
		(l, r) = list(map(int, stdin.readline().split()))
		if l <= res_l <= r or l <= res_r <= r:
			if l < res_l:
				res_l = l
			if r > res_r:
				res_r = r
	print(res_r - res_l + 1)


import bisect

def insert(intervals, newInterval):
	beforeMerge = list()
	lefts = list()
	for i in range(len(intervals)):
		lefts.append(intervals[i][0])
	pos = bisect.bisect_left(lefts, newInterval[0])
	for i in range(pos):
		beforeMerge.append(intervals[i])
	beforeMerge.append(newInterval)
	for i in range(pos, len(intervals)):
		beforeMerge.append(intervals[i])
	afterMerge = list()
	n = len(beforeMerge)
	i = 0
	while i < n:
		if len(afterMerge) == 0 or afterMerge[-1][1] < beforeMerge[i][0]:
			afterMerge.append(beforeMerge[i])
		else:
			afterMerge[-1][0] = min(afterMerge[-1][0], beforeMerge[i][0])
			afterMerge[-1][1] = max(afterMerge[-1][1], beforeMerge[i][1])
		i += 1
	return afterMerge
T = int(input())
for _ in range(T):
	(n, x, m) = map(int, input().split())
	intervals = [[x, x]]
	for _ in range(m):
		(l, r) = map(int, input().split())
		overlaps = False
		for (i, j) in intervals:
			if r < i or l > j:
				continue
			overlaps = True
			break
		if overlaps:
			intervals = insert(intervals, [l, r])
	num = 0
	for (i, j) in intervals:
		num += j - i + 1
	print(num)


for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	lp = -1
	rp = -1
	ans = 0
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if lp == -1 and rp == -1 and (l <= x) and (r >= x):
			lp = l
			rp = r
		elif l <= lp and r >= rp:
			lp = l
			rp = r
		elif l >= lp and l <= rp and (r >= rp):
			rp = r
		elif l <= lp and r >= lp and (r <= rp):
			lp = l
	if lp <= x and rp >= x:
		ans += rp - lp + 1
	print(max(1, ans))


for _ in range(int(input())):
	(n, x, m) = [int(i) for i in input().split()]
	b = []
	for i in range(m):
		b.append(tuple([int(j) for j in input().split()]))
	isStart = True
	total = 0
	(l, r) = (x, x)
	for bound in b:
		if l >= bound[0] and l <= bound[1]:
			l = bound[0]
			r = max(r, bound[1])
			isStart = False
		elif r >= bound[0] and r <= bound[1]:
			l = min(l, bound[0])
			r = bound[1]
			isStart = False
	print(r - l + 1)


import sys

def answer(n, x, m, l, r):
	lptr = x
	rptr = x
	for i in range(m):
		if l[i] < lptr and r[i] >= lptr:
			lptr = l[i]
		if r[i] > rptr and l[i] <= rptr:
			rptr = r[i]
	k = rptr - lptr + 1
	return k

def main():
	t = int(input())
	while t:
		(n, x, m) = [int(i) for i in sys.stdin.readline().split()]
		l = [0] * m
		r = [0] * m
		for j in range(m):
			(l[j], r[j]) = [int(i) for i in sys.stdin.readline().split()]
		print(answer(n, x, m, l, r))
		t -= 1
	return
main()


def solve():
	(n, x, m) = map(int, input().split())
	(s, e) = (x, x)
	for _ in range(m):
		(l, r) = map(int, input().split())
		if e < l or r < s:
			continue
		s = min(s, l)
		e = max(e, r)
	print(e - s + 1)
t = int(input())
for _ in range(t):
	solve()


for z in range(int(input())):
	(n, x, m) = map(int, input().split())
	x1 = x2 = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if b >= x1 and a <= x2:
			if a <= x1:
				x1 = a
			if b >= x2:
				x2 = b
	print(x2 - x1 + 1)


def pos_ind(n, x, m, ops):
	var = 0
	for i in range(m):
		l = ops[i]
		if x <= l[1] and x >= l[0]:
			var = 1
			ind = i
			break
	if var == 0:
		return 1
	else:
		a = ops[ind][0]
		b = ops[ind][1]
		for i in range(ind, m - 1):
			l = ops[i + 1]
			if l[0] <= b and l[1] >= a:
				a = min(a, l[0])
				b = max(b, l[1])
		return b - a + 1

def new_fun(n, x, m, ops):
	L = [0] * n
	L[x - 1] = 1
	for l in ops:
		a = l[0] - 1
		b = l[1] - 1
		var = 0
		for i in range(a, b + 1):
			if L[i] == 1:
				var = 1
				break
		if var == 1:
			for i in range(a, b + 1):
				L[i] = 1
	return L.count(1)
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	ops = []
	for j in range(m):
		l = list(map(int, input().split()))
		ops.append(l)
	print(pos_ind(n, x, m, ops))


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)


from sys import stdin, stdout
from sys import maxsize

def solve(b, r):
	for el in b:
		if el[0] <= r[1] <= el[1] or el[1] >= r[0] >= el[0]:
			r[0] = min(r[0], el[0])
			r[1] = max(r[1], el[1])
	return r
	pass
test = 1
test = int(input())
for t in range(0, test):
	(n, x, m) = list(map(int, input().split()))
	brr = [list(map(int, input().split())) for i in range(m)]
	ran = [x, x]
	ans = solve(brr, ran)
	print(ans[1] - ans[0] + 1)


import collections
tests = int(input())
for _ in range(tests):
	arr = [int(a) for a in input().strip().split(' ')]
	n = arr[0]
	l = arr[1]
	u = arr[1]
	m = arr[2]
	for _ in range(m):
		arr = [int(a) for a in input().strip().split(' ')]
		if arr[1] >= l and arr[1] <= u:
			l = min(arr[0], l)
		elif arr[0] <= u and arr[0] >= l:
			u = max(arr[1], u)
		elif arr[0] <= l and arr[1] >= u:
			l = arr[0]
			u = arr[1]
	print(u - l + 1)


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

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


t = int(input())
for i in range(0, t):
	a = [int(x) for x in input().split(' ')]
	c = a[1]
	d = a[1]
	for j in range(0, a[2]):
		b = [int(z) for z in input().split(' ')]
		if c >= b[0] and d <= b[1]:
			c = b[0]
			d = b[1]
		elif b[0] < c and (b[1] >= c and b[1] <= d):
			c = b[0]
		elif (b[0] >= c and b[0] <= d) and b[1] > d:
			d = b[1]
	print(d - c + 1)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	i = x
	j = x
	for _ in range(m):
		(l, r) = [int(x) for x in input().split()]
		if l <= i and r >= i or (l <= j and r >= j):
			i = min(i, l)
			j = max(j, r)
	print(j - i + 1)


from math import ceil, floor
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(rl, rh, f) = (0, 0, 0)
	for i in range(m):
		(l, h) = map(int, input().split())
		if (x >= l and x <= h) and f == 0:
			rl = l
			rh = h
			f = 1
		if l <= rl and h >= rl:
			rl = l
			if rh <= h:
				rh = h
		if l <= rh and h >= rh:
			rh = h
	print(rh - rl + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	la = r = x
	for i in range(m):
		(p, q) = map(int, input().split())
		if p > r or q < la:
			continue
		else:
			la = min(la, p)
			r = max(r, q)
	print(r - la + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	mn = x
	mx = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= mn <= r:
			mn = l
		if l <= mx <= r:
			mx = r
	print(mx - mn + 1)


import sys
fast_reader = sys.stdin.readline

def input():
	return fast_reader().strip()

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

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, x, m) = sep_input()
	l = []
	r = []
	(a, b) = (x, x)
	for i in range(m):
		(t1, t2) = sep_input()
		l.append(t1)
		r.append(t2)
		if t1 <= a and t2 >= b:
			a = t1
			b = t2
		elif t1 <= a <= t2 <= b:
			a = t1
		elif a <= t1 <= b <= t2:
			b = t2
	print(b - a + 1)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return list(sys.stdin.readline().strip())
t = II()
for q in range(t):
	(n, x, m) = MI()
	ml = n
	mr = 0
	boo = False
	for z in range(m):
		(l, r) = MI()
		if boo:
			if l < ml and r >= ml:
				ml = l
			if r > mr and l <= mr:
				mr = r
		if boo == False:
			if x >= l and x <= r:
				boo = True
				ml = l
				mr = r
	print(max(mr - ml + 1, 1))


import sys
input = sys.stdin.buffer.readline
for _ in [0] * int(input()):
	(n, x, m) = list(map(int, input().split()))
	mink = maxk = x
	for _ in [0] * m:
		(l, r) = list(map(int, input().split()))
		if l <= maxk and r > maxk:
			maxk = r
		if r >= mink and l < mink:
			mink = l
	print(maxk - mink + 1)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	p = x
	s = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if s <= r:
			if s > l:
				s = l
		if p >= l:
			if p < r:
				p = r
	print(p - s + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	k = []
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= x and b >= x:
			k.append([a, b])
		else:
			v = 0
			for j in k:
				if a >= j[0] and a <= j[1] or (b <= j[1] and b >= j[0]):
					v = 1
					break
			if v:
				k.append([a, b])
	if not k:
		print(1)
		continue
	k.sort()
	c = [k[0]]
	for j in range(1, len(k)):
		if k[j][0] <= c[-1][1]:
			c[-1] = [c[-1][0], max(k[j][1], c[-1][1])]
		else:
			c.append(k[j])
	ans = 0
	for i in c:
		ans += i[1] - i[0] + 1
	print(ans)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	c = 1
	x1 = x
	x2 = x
	for j in range(m):
		(l, r) = map(int, input().split())
		if x1 != x2:
			if l <= x1 and r <= x2 and (r >= x1):
				c += x1 - l
				x1 = l
			elif l <= x1 and r >= x2:
				c += x1 - l
				c += r - x2
				x1 = l
				x2 = r
			elif l >= x1 and l <= x2 and (r >= x2):
				c += r - x2
				x2 = r
		elif x >= l and x <= r:
			c += r - l
			x1 = l
			x2 = r
	print(c)


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	arr = [int(x) for x in stdin.readline().split()]
	n = arr[0]
	x = arr[1]
	m = arr[2]
	l_most = x
	r_most = x
	for op in range(m):
		arr = [int(x) for x in stdin.readline().split()]
		li = arr[0]
		ri = arr[1]
		if li <= l_most and ri <= r_most and (ri >= l_most):
			l_most = li
		elif li >= l_most and li <= r_most and (ri >= r_most):
			r_most = ri
		elif li <= l_most and ri >= r_most:
			l_most = li
			r_most = ri
	stdout.write(str(r_most - l_most + 1) + '\n')


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


t = int(input())
for g in range(t):
	(n, x, m) = map(int, input().split())
	L = []
	R = []
	f = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if x >= l and x <= r:
			R.append(r)
			L.append(l)
			f = 1
		elif f == 1:
			if l >= min(L) and l <= max(R) or (r <= max(R) and r >= min(L)):
				L.append(l)
				R.append(r)
	if f == 0:
		print(1)
	else:
		print(max(R) - min(L) + 1)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	x1 = x - 1
	x2 = x - 1
	for j in range(m):
		(l, d) = map(int, input().split())
		if l - 1 <= x1 <= d - 1 or l - 1 <= x2 <= d - 1:
			x1 = min(x1, l - 1)
			x2 = max(x2, d - 1)
	print(x2 - x1 + 1)


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	_v_ = II()
	for _ in range(_v_):
		(n, x, m) = MI()
		q = [x, x]
		for __ in range(m):
			(l, r) = MI()
			(lq, rq) = q
			if max(lq, l) <= min(rq, r):
				q[0] = min(lq, l)
				q[1] = max(rq, r)
		(lq, rq) = q
		print(rq - lq + 1)
main()


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	swapper = []
	for i in range(m):
		swapper.append(list(map(int, input().split())))
	flag = 0
	uu = -1
	ll = -1
	for i in range(len(swapper)):
		if flag == 0:
			if x >= swapper[i][0] and x <= swapper[i][1]:
				flag = 1
				ll = swapper[i][0]
				uu = swapper[i][1]
		elif swapper[i][0] >= ll and swapper[i][0] <= uu:
			uu = max(uu, swapper[i][1])
		elif swapper[i][1] >= ll and swapper[i][1] <= uu:
			ll = min(ll, swapper[i][0])
		elif swapper[i][0] <= ll and swapper[i][1] >= uu:
			uu = swapper[i][1]
			ll = swapper[i][0]
	print(uu - ll + 1)


from math import inf as inf
from math import *
from collections import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, x, m) = map(int, input().split())
	ra = 0
	(maxl, maxr) = (float('inf'), -float('inf'))
	(chxl, chxr) = (x, x)
	flag = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if not (chxl <= l and chxr >= r or (chxl >= l and chxr >= r and (chxl <= r)) or (l >= chxl and l <= chxr) or (chxl >= l and chxr <= r)):
			continue
		else:
			chxl = min(l, r, chxl)
			chxr = max(l, r, chxr)
			maxl = min(l, r, maxl)
			maxr = max(l, r, maxr)
	if maxl != float('inf'):
		ra = chxr - chxl + 1
	else:
		ra = 1
	print(ra)


def solution(A, n, x, m):
	I = [x, x]
	for (l, r) in A:
		if max(I[0], l) <= min(I[1], r):
			I = [min(I[0], l), max(I[1], r)]
	return I[1] - I[0] + 1
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split(' '))
	A = []
	for _ in range(m):
		(l, r) = map(int, input().split(' '))
		A.append([l, r])
	print(solution(A, n, x, m))


def gns():
	return list(map(int, input().split()))
t = int(input())
for i in range(t):
	(n, x, m) = gns()
	(l, r) = (x, x)
	for i in range(m):
		(tl, tr) = gns()
		if tr < l or tl > r:
			continue
		l = min(l, tl)
		r = max(r, tr)
	print(r - l + 1)


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		a = []
		(n, x, m) = map(int, input().split())
		for i in range(m):
			(l, r) = map(int, input().split())
			a.append([l, r])
		ans = 0
		(L, R) = (x, x)
		for i in range(m):
			if a[i][1] < L or a[i][0] > R:
				continue
			else:
				L = min(L, a[i][0])
				R = max(R, a[i][1])
		print(R - L + 1)


import sys
from sys import stdin
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x, m) = [int(j) for j in input().split()]
	dp = []
	temp = 0
	low = 0
	high = 0
	check = 0
	dic = {}
	for i in range(10000):
		dic[i] = i + 100
	dp = [x, x]
	for i in range(m):
		(l, r) = (int(x) for x in input().split())
		if l >= dp[0] and l <= dp[1] and (r >= dp[1]):
			dp[1] = r
		if r >= dp[0] and r <= dp[1] and (l <= dp[0]):
			dp[0] = l
		if l <= dp[0] and r >= dp[1]:
			dp[0] = l
			dp[1] = r
	print(dp[1] - dp[0] + 1)


def solve_test_case(t):
	(n, x, m) = parse_array(int)
	left = x
	right = x
	for i in range(m):
		(li, ri) = parse_array(int)
		if left <= ri and li <= right:
			left = min(left, li)
			right = max(right, ri)
	print(right - left + 1)

def parse_array(f):
	return list(map(f, input().split()))

def solve():
	T = int(input())
	for t in range(T):
		solve_test_case(t)
solve()


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


from collections import defaultdict
it = lambda : list(map(int, input().strip().split()))

def solve():
	(n, x, m) = it()
	lo = hi = x
	for _ in range(m):
		(l, r) = it()
		assert lo <= hi and l <= r
		if r < lo or hi < l:
			continue
		if lo <= l <= r <= hi:
			continue
		if l <= lo <= hi <= r:
			lo = l
			hi = r
			continue
		if l <= lo <= r <= hi:
			lo = l
			continue
		if lo <= l <= hi <= r:
			hi = r
			continue
		assert False
	return min(n, hi) - max(1, lo) + 1
T = int(input())
for _ in range(T):
	print(solve())


for uhnpnewrungppwieurnpifwnipwcunidnpuogewuygrbcuiqjiof3nmdilk in range(int(input())):
	(n, x, m) = map(int, input().split())
	(lb, hb) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		if lb >= a and lb <= b or (hb >= a and hb <= b):
			if lb > a:
				lb = a
			if hb < b:
				hb = b
	print(1 + hb - lb)


t = int(input())
count = 0
while count < t:
	count += 1
	l = list(map(int, input().split(' ')))
	tcount = 0
	ans = 1
	left = l[1]
	right = l[1]
	while tcount < l[2]:
		tcount += 1
		L = list(map(int, input().split(' ')))
		nleft = L[0]
		nright = L[1]
		if nleft <= left and nright >= right:
			ans += left - nleft + nright - right
			left = nleft
			right = nright
		elif nleft < left and nright >= left:
			ans += left - nleft
			left = nleft
		elif nright > right and nleft <= right:
			ans += nright - right
			right = nright
	print(ans)


import getopt
import sys
import math
onlyCase = -1
verbose = False
try:
	(opts, args) = getopt.getopt(sys.argv[1:], 'vc:', ['case='])
except getopt.GetoptError as err:
	print(str(err))
	sys.exit(2)
for (o, a) in opts:
	if o in ('-c', '--case'):
		onlyCase = int(a)
	elif o == '-v':
		verbose = True
	else:
		sys.exit()
ncases = int(input())
for c in range(1, ncases + 1):
	(N, X, M) = [int(x) for x in input().split()]
	A = []
	for i in range(M):
		A.append([int(x) for x in input().split()])
	if onlyCase != -1 and onlyCase != c:
		continue
	if verbose:
		print(A)
	sol = [X, X]
	for a in A:
		if verbose:
			print('sol[%d,%d] - checking [%d,%d]' % (sol[0], sol[1], a[0], a[1]))
		if sol[1] >= a[0] and sol[1] <= a[1]:
			sol[1] = a[1]
		if sol[0] >= a[0] and sol[0] <= a[1]:
			sol[0] = a[0]
	print('%d' % (1 + sol[1] - sol[0]))


t = int(input())
while t > 0:
	t -= 1
	(n, x, m) = map(int, input().split())
	domain = [x, x]
	while m > 0:
		m -= 1
		(a, b) = map(int, input().split())
		l = min(a, b)
		r = max(a, b)
		if l <= domain[0] and r >= domain[1]:
			domain[0] = l
			domain[1] = r
		elif l <= domain[0] and r >= domain[0] and (r <= domain[1]):
			domain[0] = l
		elif l >= domain[0] and l <= domain[1] and (r >= domain[1]):
			domain[1] = r
	print(domain[1] - domain[0] + 1)


def solve(n, x, m, data):
	f = t = x
	for (l, r) in data:
		if l <= f <= r or l <= t <= r or (f < l and t > r):
			(f, t) = (min(f, l), max(t, r))
	return t - f + 1
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	data = []
	for _ in range(m):
		(l, r) = map(int, input().split())
		data.append((l, r))
	print(solve(n, x, m, data))


def shuffle(n, x, m, a):
	xincluded = False
	initial = None
	final = None
	for i in range(m):
		if xincluded == False:
			if a[i][0] <= x and a[i][1] >= x:
				xincluded = True
				initial = a[i][0]
				final = a[i][1]
		elif a[i][0] <= initial and a[i][1] >= initial or (a[i][0] <= final and a[i][1] >= final):
			initial = min(a[i][0], initial)
			final = max(a[i][1], final)
	if initial == None:
		print(1)
		return
	else:
		print(final - initial + 1)
		return
t = int(input())
a = []
for i in range(t):
	(n, x, m) = list(map(int, input().split(' ')))
	ins = []
	for j in range(m):
		ins.append(list(map(int, input().split(' '))))
	a.append([n, x, m, ins])
for y in a:
	shuffle(*y)


t = int(input())
while t > 0:
	(a, b, c) = input().split()
	n = int(a)
	x = int(b)
	m = int(c)
	count = 0
	x1 = x2 = x
	for i in range(m):
		(a, b) = input().split()
		c = int(a)
		d = int(b)
		if c <= x1 and d >= x1:
			count += x1 - c
			x1 = c
		if d >= x2 and c <= x2:
			count += d - x2
			x2 = d
	if count > n:
		print(n)
	else:
		print(count + 1)
	t -= 1


for _ in range(int(input())):
	(n, x, q) = map(int, input().split())
	(l, r) = (x, x)
	for j in range(q):
		(L, R) = map(int, input().split())
		if max(L, l) <= min(R, r):
			l = min(l, L)
			r = max(r, R)
	print(r - l + 1)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def possible(l, r, lx, rx):
	if l < lx and r < lx:
		return False
	if l > rx:
		return False
	if lx < l and rx < l:
		return False
	if lx > r:
		return False
	return True
for t in range(int(input())):
	(n, x, q) = map(int, input().split())
	lx = x
	rx = x
	for i in range(q):
		(l, r) = map(int, input().split())
		if l <= x <= r or possible(l, r, lx, rx) == 1:
			lx = min(lx, l)
			rx = max(rx, r)
	print(rx - lx + 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 i in range(t):
	(n, x, m) = map(int, input().split())
	l = []
	for j in range(m):
		l.append(list(map(int, input().split())))
	ans = 0
	k = m - 1
	for j in range(m):
		if l[j][0] <= x <= l[j][1]:
			k = j
			ans += l[j][1] - l[j][0] + 1
			break
	a = l[k]
	for j in range(k + 1, m):
		if a[1] >= l[j][1] >= a[0]:
			if l[j][0] < a[0]:
				ans += a[0] - l[j][0]
				a = [l[j][0], a[1]]
		elif a[0] <= l[j][0] <= a[1]:
			if l[j][1] > a[1]:
				ans += l[j][1] - a[1]
				a = [a[0], l[j][1]]
		elif a[0] > l[j][0] and a[1] < l[j][1]:
			ans = l[j][1] - l[j][0] + 1
			a = l[j]
	print(max(ans, 1))


for nt in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = []
	for i in range(m):
		(l, r) = map(int, input().split())
		a.append((l, r))
	(s, e) = (x, x)
	for i in range(m):
		(l, r) = (a[i][0], a[i][1])
		if s >= l and s <= r:
			s = min(s, l)
		if e >= l and e <= r:
			e = max(e, r)
	print(e - s + 1)


t = int(input())
for q in range(t):
	(n, x, m) = [int(i) for i in input().split()]
	interval = [x - 1, x - 1]
	for i in range(m):
		inp = [int(i) - 1 for i in input().split()]
		if inp[1] >= interval[1] and inp[0] <= interval[1] or (inp[0] <= interval[0] and inp[1] >= interval[0]):
			interval = [min(interval[0], inp[0]), max(interval[1], inp[1])]
	print(interval[1] - interval[0] + 1)


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)

def main():
	t = input1()
	for ci in range(t):
		(n, x, m) = input3()
		done = [(x, x)]
		for i in range(m):
			(a, b) = input2()
			done.sort()
			for (u, v) in done:
				if a >= u and b <= v:
					continue
				elif a >= u and a <= v:
					done.remove((u, v))
					l = u
					r = max(b, v)
					if r >= l:
						done.append((l, r))
					break
				elif b >= u and b <= v:
					done.remove((u, v))
					l = a
					r = max(b, v)
					if r >= l:
						done.append((l, r))
					break
				elif u >= a and v <= b:
					done.remove((u, v))
					l = a
					r = b
					if r >= l:
						done.append((l, r))
					break
		cnt = 0
		for [u, v] in done:
			cnt += v - u + 1
		print(cnt)
	pass
READ('in.txt')
main()


from math import *
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	a = set()
	x1 = x
	x2 = x
	ans = 1
	for i in range(m):
		(l, r) = map(int, input().split())
		if x1 >= l and x1 <= r:
			a.add(l)
			a.add(r)
			if x1 > l:
				x1 = l
			if x2 < r:
				x2 = r
		elif x2 >= l and x2 <= r:
			a.add(l)
			a.add(r)
			if x1 > l:
				x1 = l
			if x2 < r:
				x2 = r
	a = list(a)
	a.sort()
	p = len(a)
	if p > 0:
		ans = a[p - 1] - a[0] + 1
	print(ans)


for t in range(int(input())):
	(n, x, m) = map(int, input().split())
	k = {x: 0}
	for i in range(m):
		(c, d) = map(int, input().split())
		if min(k) >= c and min(k) <= d or (max(k) >= c and max(k) <= d):
			k[c] = 0
			k[d] = 0
	print(max(k) - min(k) + 1)


for _t in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	(mn, mx) = (10000000000.0, -10000000000.0)
	for _ in range(m):
		(l, r) = list(map(int, input().split()))
		if l <= x and r >= x:
			mn = min(mn, l)
			mx = max(mx, r)
		elif mn == 10000000.0 and mx == -10000000.0:
			continue
		elif mn <= l and mx >= l or (mn <= r and mx >= r):
			mn = min(mn, l)
			mx = max(mx, r)
	if mx == -10000000000.0 or mn == 10000000000.0:
		print(1)
	else:
		print(mx - mn + 1)


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass

def case():
	arr = list(map(int, input().split(' ')))
	(n, x, m) = (arr[0], arr[1], arr[2])
	ll = x
	rr = x
	for _ in range(m):
		arr = list(map(int, input().split(' ')))
		(l, r) = (arr[0], arr[1])
		if l < ll and r >= ll:
			ll = l
			rr = max(rr, r)
		elif l <= rr and r > rr:
			rr = r
			min(ll, l)
	print(rr - ll + 1)
for _ in range(t):
	case()


import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	(n, x, m) = map(int, inp().split())
	mn = x
	mx = x
	ans = 0
	for i in range(m):
		(l, r) = map(int, inp().split())
		if l > mx or r < mn:
			continue
		mn = min(l, mn)
		mx = max(mx, r)
	print(mx - mn + 1)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	l = x
	r = x
	for t in range(m):
		(l1, r1) = map(int, input().split())
		if l1 <= l <= r1 or l1 <= r <= r1:
			l = min(l, l1)
			r = max(r, r1)
	print(r - l + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	c = 0
	(l1, l2) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		if l1 >= a and l1 <= b or (l2 >= a and l2 <= b):
			l1 = min(l1, a)
			l2 = max(l2, b)
	print(l2 - l1 + 1)


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


t = 1
t = int(input())
for _ in range(t):
	(n, x, m) = list(map(int, input().split()))
	x -= 1
	(low, high) = (x, x)
	for __ in range(m):
		(l, r) = list(map(int, input().split()))
		l -= 1
		r -= 1
		cond1 = l <= high and r > high
		cond3 = l < low and r > high
		cond2 = l < low and r >= low
		if cond1 or cond2 or cond3:
			(low, high) = (min(low, l), max(r, high))
	print(high - low + 1)


from copy import *
from math import *
t = int(input())
for i in range(t):
	(n, x, m) = list(map(int, input().split()))
	d = [x, x]
	for j in range(m):
		(l, r) = list(map(int, input().split()))
		if d == [x, x]:
			if x >= l and x <= r:
				d = [l, r]
		elif l >= d[0] and l <= d[1] and (r >= d[1]):
			d[1] = r
		elif l <= d[0] and r <= d[1] and (r >= d[0]):
			d[0] = l
		elif l <= d[0] and r >= d[1]:
			d = [l, r]
	print(d[1] - d[0] + 1)


import sys
import math
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
t = int(input())
for case in range(t):
	(n, x, m) = map(int, input().split())
	(l_x, r_x) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l_x <= r:
			l_x = min(l_x, l)
		if r_x >= l:
			r_x = max(r_x, r)
	print(r_x - l_x + 1)


tt = int(input())
for loop in range(tt):
	(n, x, m) = map(int, input().split())
	nl = x
	nr = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= nl <= r:
			nl = l
		if l <= nr <= r:
			nr = r
	print(nr - nl + 1)


import sys
input = sys.stdin.readline
t = int(input())
ans = []
for kek 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 l <= a and r >= a or (l <= b and r >= b) or (a <= l and b >= l) or (a <= r and b >= r):
			r = max(r, b)
			l = min(l, a)
	ans.append(r - l + 1)
print(*ans, sep='\n')


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	(ll, rr) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if r >= ll:
			ll = min(l, ll)
		if l <= rr:
			rr = max(r, rr)
	print(rr - ll + 1)


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


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	curr_l = curr_r = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if l <= curr_l and r >= curr_r:
			(curr_l, curr_r) = (l, r)
		elif l <= curr_l and r >= curr_l:
			curr_l = l
		elif l <= curr_r and r >= curr_r:
			curr_r = r
	print(curr_r - curr_l + 1)


def solve():
	(n, x, m) = [int(x) for x in input().split()]
	(left_limit, right_limit) = [x, x]
	while m:
		(l, r) = [int(x) for x in input().split()]
		if left_limit >= l and right_limit <= r:
			left_limit = min(x, l)
			right_limit = max(x, r)
		elif l < left_limit and left_limit <= r <= right_limit:
			left_limit = min(left_limit, l)
		elif r > right_limit and left_limit <= l <= right_limit:
			right_limit = max(r, right_limit)
		elif l <= left_limit <= r and l <= right_limit <= r:
			left_limit = min(x, l)
			right_limit = max(x, r)
		m -= 1
	return right_limit - left_limit + 1
t = int(input())
while t:
	print(solve())
	t -= 1


inp = lambda : map(int, input().split())
(t,) = inp()
for _ in range(t):
	(n, x, m) = inp()
	(st, end) = (x, x)
	for _ in range(m):
		(i, j) = inp()
		if j < st or i > end:
			continue
		st = min(st, i)
		end = max(end, j)
	print(end - st + 1)


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

def give_range(old_range, new_range):
	[old_l, old_r] = old_range
	[l, r] = new_range
	if old_r < l or r < old_l:
		return [old_l, old_r]
	return [min(old_l, l), max(old_r, r)]

def solve():
	[n, x, m] = as_list()
	ones = [x, x]
	ops = []
	for _ in range(m):
		ops.append(as_list())
		ones = give_range(ones, ops[-1])
	[l, r] = ones
	return r - l + 1
[tests] = as_list()
for _ in range(tests):
	print(solve())


import math
for w in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	ini = 0
	fim = 0
	for i in range(m):
		sc = list(map(int, input().split()))
		if x >= sc[0] and x <= sc[1] and (ini == 0):
			ini = sc[0]
			fim = sc[1]
		elif ini >= sc[0] and ini <= sc[1]:
			ini = sc[0]
			if sc[1] > fim:
				fim = sc[1]
		elif fim >= sc[0] and fim <= sc[1]:
			fim = sc[1]
			if sc[0] < ini:
				ini = sc[0]
	print(fim - ini + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	f = 1
	l2 = 0
	r2 = -1
	for i in range(m):
		(l1, r1) = map(int, input().split())
		if f == 1:
			if x >= l1 and x <= r1:
				l2 = l1
				r2 = r1
				f = 0
		elif r1 < l2 or r2 < l1:
			a = 0
		else:
			l2 = min(l2, l1)
			r2 = max(r2, r1)
	if r2 - l2 + 1 == 0:
		print(1)
	else:
		print(r2 - l2 + 1)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, x, m, ops):
	start_k = x
	end_k = x
	for op in ops:
		if op[0] <= start_k <= op[1] or op[0] <= end_k <= op[1]:
			start_k = min(start_k, op[0])
			end_k = max(end_k, op[1])
	return end_k - start_k + 1
for i in tests():
	(n, x, m) = arr_in()
	ops = mat_in(m)
	out(solve(n, x, m, ops))


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	m1 = x
	m2 = x
	for i in range(m):
		(c, d) = map(int, input().split())
		if max(m1, c) <= min(m2, d):
			m1 = min(m1, c)
			m2 = max(m2, d)
	print(m2 - m1 + 1)


for t in range(int(input())):
	(n, x, m) = [int(j) for j in input().split()]
	lf = x
	rt = x
	for i in range(m):
		(l, r) = [int(j) for j in input().split()]
		if lf > r or l > rt:
			continue
		else:
			lf = min(l, lf)
			rt = max(rt, r)
	print(min(rt - lf + 1, n))


import sys, math
from collections import deque

def solve():
	(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 >= r or (a <= l and b >= l):
			l = min(a, l)
			r = max(b, r)
	print(r - l + 1)
	return
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	l = r = -1
	flag = False
	for i in range(m):
		(li, ri) = map(int, input().split())
		if flag:
			if li <= l <= ri <= r:
				l = li
			elif l <= li <= r <= ri:
				r = ri
			elif li <= l <= r <= ri:
				l = li
				r = ri
		elif li <= x <= ri:
			flag = True
			l = li
			r = ri
	print(r - l + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def getOverlap(a, b):
	return max(0, min(a[1], b[1]) - max(a[0], b[0]) + 1)
for _ in range(int(input()) if True else 1):
	(n, x, m) = map(int, input().split())
	(alpha, omega) = (x, x)
	for _ in range(m):
		(x, y) = map(int, input().split())
		if getOverlap([x, y], [alpha, omega]):
			alpha = min(alpha, x)
			omega = max(omega, y)
	print(omega - alpha + 1)


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

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for i in range(t):
	(n, x, m) = read_ints()
	mi = x
	mx = x
	for j in range(m):
		(l, r) = read_ints()
		if mi >= l and mi <= r or (mx >= l and mx <= r):
			mi = min(mi, l)
			mx = max(mx, r)
	print(mx - mi + 1)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd
from functools import reduce
from sys import stdin, stdout

def ncr(n, r):
	r = cn(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, x, m) = list(map(int, stdin.readline().split()))
	d = {}
	(c, d) = (x, x)
	for i in range(m):
		(l, r) = list(map(int, stdin.readline().rstrip().split()))
		if x <= r and x >= l:
			if c > l:
				c = l
			if d < r:
				d = r
		elif r >= c and r <= d or (l >= c and l <= d):
			if c > l:
				c = l
			if d < r:
				d = r
	ans = d - c + 1
	print(ans)


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


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
tt = I()
for ii in range(tt):
	(n, x, m) = IL()
	(st, en) = (x, x)
	for i in range(m):
		(x, y) = IL()
		if x <= en and x >= st or (y >= st and y <= en) or (x <= st and y >= en):
			st = min(st, x)
			en = max(en, y)
	print(en - st + 1)
	pass


from math import *
for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	l = []
	for i in range(m):
		(a, b) = map(int, input().split())
		l.append([a, b])
	tmp = 0
	min1 = x
	max1 = x
	for i in range(m):
		if l[i][1] <= max1 and l[i][1] >= min1:
			tmp1 = min(l[i][0], l[i][1], min1, max1)
			tmp2 = max(l[i][0], l[i][1], min1, max1)
			min1 = tmp1
			max1 = tmp2
		elif l[i][0] >= min1 and l[i][0] <= max1:
			tmp1 = min(l[i][0], l[i][1], min1, max1)
			tmp2 = max(l[i][0], l[i][1], min1, max1)
			min1 = tmp1
			max1 = tmp2
		elif l[i][0] <= min1 and l[i][1] >= max1:
			tmp1 = min(l[i][0], l[i][1], min1, max1)
			tmp2 = max(l[i][0], l[i][1], min1, max1)
			min1 = tmp1
			max1 = tmp2
	max1 = max1 - min1
	print(max1 + 1)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, X, M, ops):
	lo = X
	hi = X
	for (l, r) in ops:
		if hi < l or r < lo:
			continue
		lo = min(lo, l)
		hi = max(hi, r)
	return hi - lo + 1
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, X, M) = [int(x) for x in input().split()]
	X -= 1
	ops = [[int(x) - 1 for x in input().split()] for i in range(M)]
	ans = solve(N, X, M, ops)
	print(ans)


T = int(input())

def findK(arr):
	for i in range(0, len(arr)):
		if contains1(arr[i], x):
			K = i
			return K
	return -1

def solve(arr, x, K):
	(a, b) = arr[K]
	s = arr[K]
	for i in range(K, len(arr) - 1):
		if hasOverlap(s, arr[i + 1]):
			(a1, b1) = arr[i + 1]
			if a1 < a:
				a = a1
			if b1 > b:
				b = b1
			s = [a, b]
	return b - a + 1

def contains1(i, x):
	(c, d) = i
	if c <= x <= d:
		return 1
	else:
		return 0

def hasOverlap(i1, i2):
	(c1, d1) = i1
	(c2, d2) = i2
	if c2 <= c1 <= d2:
		return (c2, max(d1, d2))
	if c1 <= c2 <= d1:
		return (c1, max(d1, d2))
	return 0
while T > 0:
	(n, x, m) = [int(el) for el in input().rstrip().split(' ')]
	arr = []
	for i in range(0, m):
		(c, d) = [int(el) for el in input().rstrip().split(' ')]
		arr.append([c, d])
	K = findK(arr)
	if K != -1:
		ans = solve(arr, x, K)
	else:
		ans = 1
	print(ans)
	T -= 1


import os
import random
import sys
from io import BytesIO, IOBase
import math

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

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(inputNum()):
		(n, x, m) = inputVars()
		check = False
		minRange = float('inf')
		maxRange = float('-inf')
		for pos in range(m):
			temp = inputIntArray()
			if check and temp[1] >= minRange and (temp[0] <= maxRange):
				minRange = min(minRange, temp[0])
				maxRange = max(maxRange, temp[1])
			elif not check and x >= temp[0] and (x <= temp[1]):
				check = True
				minRange = temp[0]
				maxRange = temp[1]
		if not check:
			print(1)
		else:
			print(maxRange - minRange + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


test = int(input())
for _ in range(test):
	(x, y, z) = [int(x) for x in input().split()]
	maxx = minn = y
	while z > 0:
		(i, j) = [int(x) for x in input().split()]
		if j >= maxx and i <= maxx:
			maxx = j
			minn = min(minn, i)
		elif j >= minn and i <= minn:
			maxx = max(maxx, j)
			minn = i
		z -= 1
	print(maxx - minn + 1)


import sys
import heapq
import random
import collections
import math

def solve(n, x, ops):
	(left, right) = (x, x)
	for (a, b) in ops:
		if left <= a <= right or left <= b <= right or a <= left <= b or (a <= right <= b):
			left = min(a, left)
			right = max(b, right)
		console(left, right)
	return right - left + 1

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(n, x, nrows) = list(map(int, input().split()))
	grid = []
	for _ in range(nrows):
		grid.append(list(map(int, input().split())))
	res = solve(n, x, grid)
	print(res)


T = int(input())
for t in range(T):
	(n, x, m) = map(int, input().split())
	start = x
	end = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= start and r >= start:
			start = l
		if l <= end and r >= end:
			end = r
	print(end - start + 1)


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)


t = int(input())
for _ in range(t):
	nxm = list(map(int, input().split()))
	(n, x, m) = nxm
	ops = []
	for i in range(m):
		ops.append(list(map(int, input().split())))
	x_found = False
	(bottom, top) = (0, 0)
	for o in ops:
		if not x_found:
			if o[0] <= x <= o[1]:
				x_found = True
				(bottom, top) = (o[0], o[1])
			else:
				continue
		if o[0] <= bottom and o[1] >= top:
			(bottom, top) = (o[0], o[1])
		elif o[0] <= bottom and bottom <= o[1] <= top:
			bottom = o[0]
		elif o[1] >= top and bottom <= o[0] <= top:
			top = o[1]
	res = top - bottom + 1
	print(res)


cases = int(input())
for i in range(cases):
	(n, x, m) = [int(p) for p in input().split()]
	gl = x
	gr = x
	for j in range(m):
		(l, r) = [int(p) for p in input().split()]
		if l <= gr <= r or l <= gl <= r:
			if gl > l:
				gl = l
			if gr < r:
				gr = r
	print(gr - gl + 1)


def inter(a, b):
	arr = [a, b]
	arr.sort()
	(a, b) = arr
	if b[0] <= a[1] and b[0] >= a[0]:
		return True
	return False

def union(a, b):
	return [min(a[0], b[0]), max(a[1], b[1])]

def diff(ini, a):
	return max(a[1] - ini[1], 0) + max(ini[0] - a[0], 0)
for i in range(int(input())):
	(n, k, m) = [int(i) for i in input().split()]
	arr = []
	for _ in range(m):
		arr.append([int(i) for i in input().split()])
	initial = [k, k]
	ans = 1
	for i in arr:
		if inter(initial, i):
			ans += diff(initial, i)
			initial = union(initial, i)
		else:
			continue
	print(ans)


test = int(input())
for _ in range(test):
	(n, x, m) = map(int, input().split())
	ran = [x, x]
	for _ in range(m):
		(l, r) = map(int, input().split())
		if l <= ran[0]:
			if r >= ran[0]:
				ran[0] = min(l, ran[0])
				ran[1] = max(r, ran[1])
		elif l <= ran[1]:
			ran[0] = min(l, ran[0])
			ran[1] = max(r, ran[1])
	print(ran[1] - ran[0] + 1)


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


import math
for test in range(int(input())):
	(n, x, m) = map(int, input().split())
	ra = x
	la = x
	for k in range(m):
		(r, l) = map(int, input().split())
		if r < ra and l >= ra or (r <= la and l > la):
			if r < ra:
				ra = r
			if l > la:
				la = l
	print(la - ra + 1)


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	(n, x, m) = read_int_arr()
	(cur_start, cur_end) = (x, x)
	for _ in range(m):
		(l, r) = read_int_arr()
		if l > cur_end or cur_start > r:
			continue
		cur_start = min(l, cur_start)
		cur_end = max(r, cur_end)
	print(cur_end - cur_start + 1)

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


for test_case in range(int(input())):
	(size, index_of_one, ops) = map(int, input().split())
	upper_bound = index_of_one
	lower_bound = index_of_one
	for operation in range(ops):
		(c, d) = map(int, input().split())
		if d >= upper_bound >= c or d >= lower_bound >= c:
			upper_bound = max(upper_bound, d)
			lower_bound = min(lower_bound, c)
	print(upper_bound - lower_bound + 1)


t = int(input())
for v in range(t):
	(n, x, m) = map(int, input().split(' '))
	op = []
	for i in range(m):
		li = list(map(int, input().split(' ')))
		op.append(li)
	mi = x
	ma = x
	i = 0
	while i < m:
		if mi >= op[i][0] and ma <= op[i][1]:
			mi = op[i][0]
			ma = op[i][1]
		elif mi <= op[i][1] and op[i][0] <= mi:
			mi = op[i][0]
		elif ma <= op[i][1] and op[i][0] <= ma:
			ma = op[i][1]
		i += 1
	print(ma - mi + 1)


t = int(input())

def solution(n, x, m):
	(s, e) = (x, x)
	for i in range(m):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		if l < s <= r:
			s = l
		if l <= e < r:
			e = r
	return e - s + 1
for i in range(t):
	(n, x, m) = input().split()
	(n, x, m) = (int(n), int(x), int(m))
	print(solution(n, x, m))


import math
t = int(input())
for w in range(t):
	(n, x, m) = (int(i) for i in input().split())
	c = 0
	ct = 1
	for i in range(m):
		(l, r) = (int(i) for i in input().split())
		if x >= l and x <= r and (c == 0):
			ct = r - l + 1
			left = l
			right = r
			c = 1
		elif c == 1:
			if l <= left and r >= left:
				right = max(right, r)
				left = min(left, l)
				ct = right - left + 1
			elif l <= right and r >= right:
				left = min(left, l)
				right = max(right, r)
				ct = right - left + 1
	print(ct)


import sys
readline = sys.stdin.readline

def solve():
	(N, X, M) = map(int, readline().split())
	LR = [tuple(map(int, readline().split())) for i in range(M)]
	(a, b) = (X, X)
	for (l, r) in LR:
		if max(a, l) <= min(b, r):
			a = min(a, l)
			b = max(b, r)
	print(b - a + 1)
T = int(readline())
for t in range(T):
	solve()


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


def merge(a, b):
	if a[1] < b[0] or b[1] < a[0]:
		return a
	return [min(a[0], b[0]), max(a[1], b[1])]
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	oper = [list(map(int, input().split())) for _ in range(m)]
	curr = [x, x]
	for o in oper:
		curr = merge(curr, o)
	print(curr[1] - curr[0] + 1)


t = int(input())

def solve():
	(n, x, m) = map(int, input().split())
	l = r = x
	while m > 0:
		(l_i, r_i) = map(int, input().split())
		if l in range(l_i, r_i + 1) or r in range(l_i, r_i + 1):
			l = min(l, l_i)
			r = max(r, r_i)
		m -= 1
	print(r - l + 1)
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(low, up) = (x, x)
	for i in range(m):
		(l1, r1) = map(int, input().split())
		if r1 < low or l1 > up:
			continue
		low = min(low, l1)
		up = max(up, r1)
	print(up - low + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	ct = 0
	(rl, rr) = map(int, input().split())
	if not rl <= x <= rr:
		rl = x
		rr = x
	for i in range(m - 1):
		(l, r) = map(int, input().split())
		if not (r < rl or l > rr):
			rl = min(l, rl)
			rr = max(r, rr)
	print(rr - rl + 1)


def solve():
	(n, x, m) = map(int, input().split())
	LR = [tuple(map(int, input().split())) for _ in range(m)]
	a = x
	b = x
	for (l, r) in LR:
		if l <= a and a <= r or (a <= l and l <= b):
			a = min(l, a)
			b = max(r, b)
	return b - a + 1

def main():
	T = int(input())
	for _ in range(T):
		print(solve())
main()


import sys
input = sys.stdin.readline

def solve():
	(N, X, M) = map(int, input().split())
	t = 0
	LEFT = X
	RIGHT = X
	L = []
	for i in range(M):
		(L, R) = map(int, input().split())
		if LEFT > R or RIGHT < L:
			continue
		else:
			LEFT = min(L, LEFT)
			RIGHT = max(R, RIGHT)
	print(RIGHT - LEFT + 1)
for _ in range(int(input())):
	solve()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(n, x, m) = map(int, sys.stdin.readline().split())
	nowl = x
	nowr = x
	for _ in range(m):
		(l, r) = map(int, sys.stdin.readline().split())
		if l <= nowl <= r or l <= nowr <= r:
			nowl = min(nowl, l)
			nowr = max(nowr, r)
	print(nowr - nowl + 1)


from sys import stdin
A = int(stdin.readline())
for k in range(0, A):
	B = list(map(int, stdin.readline().split()))
	n = B[0]
	x = B[1]
	m = B[2]
	ini = x
	end = x
	for t in range(0, m):
		C = list(map(int, stdin.readline().split()))
		if C[0] > end:
			continue
		if ini <= C[0] <= end:
			end = max(end, C[1])
			continue
		if C[0] < ini:
			if C[1] >= ini:
				ini = C[0]
				end = max(end, C[1])
	print(end - ini + 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)


t = int(input())
for i in range(t):
	(n, x, m) = list(map(int, input().split()))
	lis = []
	ans = [x, x]
	for j in range(m):
		(l, r) = list(map(int, input().split()))
		lis.append([l, r])
	for j in range(m):
		if ans[0] >= lis[j][0] and ans[0] <= lis[j][1]:
			ans[0] = lis[j][0]
		if ans[1] <= lis[j][1] and ans[1] >= lis[j][0]:
			ans[1] = lis[j][1]
	print(ans[1] - ans[0] + 1)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	lr = [list(map(int, input().split())) for j in range(m)]
	(mi, ma) = (x, x)
	for j in lr:
		if j[0] > ma or j[1] < mi or mi <= j[0] <= j[1] <= ma:
			continue
		if mi > j[0]:
			mi = j[0]
		if ma < j[1]:
			ma = j[1]
	print(ma - mi + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	li = 0
	ri = 0
	c = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x and x <= r and (c == 0):
			li = l
			ri = r
			c = 1
		elif c == 1 and (r >= li and l <= li):
			li = min(li, l)
			ri = max(ri, r)
		elif c == 1 and l <= ri and (r >= ri):
			li = min(li, l)
			ri = max(ri, r)
	if c == 0:
		print(1)
	else:
		print(ri - li + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(y, z) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		if a > z or b < y or (a >= y and b <= z):
			continue
		if b > z:
			z = b
		if a < y:
			y = a
	print(z - y + 1)


from sys import *
input = stdin.readline
for u in range(int(input())):
	(n, k, m) = map(int, input().split())
	(x, y) = (k, k)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l > y or r < x:
			continue
		else:
			x = min(x, l)
			y = max(y, r)
	print(y - x + 1)


def main():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		y = x
		for _ in range(m):
			(l, r) = map(int, input().split())
			if l <= x <= r or l <= y <= r:
				(x, y) = (min(x, l), max(y, r))
		print(y - x + 1)
main()


t = int(input())
while t:
	(n, x, m) = map(int, input().split())
	(l_answ, r_answ) = (10 ** 9 + 1, -1)
	(l_last, r_last) = (-1, -1)
	for op in range(m):
		(l, r) = map(int, input().split())
		if x >= l and x <= r:
			if l_answ > l:
				l_answ = l
			if r_answ < r:
				r_answ = r
		elif r_answ != -1:
			if r >= l_answ and l <= r_answ:
				if l_answ > l:
					l_answ = l
				if r_answ < r:
					r_answ = r
		(l_last, r_last) = (l, r)
	if l_answ == 10 ** 9 + 1 or r_answ == -1:
		print(1)
	else:
		print(r_answ - l_answ + 1)
	t -= 1


T = int(input())
for i in range(T):
	(n, p, q) = map(int, input().split())
	gma = p
	gmi = p
	t = 1
	for i in range(q):
		(a, b) = map(int, input().split())
		lma = max(a, b)
		lmi = min(a, b)
		if gma <= lma and gma >= lmi or (gmi <= lma and gmi >= lmi):
			gma = max(gma, lma)
			gmi = min(gmi, lmi)
	print(gma - gmi + 1)


T = int(input())
for _ in range(T):
	(N, X, M) = 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)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	left = -1
	right = -1
	flag = 0
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= x <= b and flag == 0:
			left = a
			right = b
			flag = 1
		if flag == 1 and a < left and (b >= left):
			left = a
		if flag == 1 and b > right and (a <= right):
			right = b
	if left == -1 and right == -1:
		print(1)
	else:
		print(right - left + 1)


t = int(input())
while t > 0:
	flag = 0
	mini = 2 ** 29 - 1
	maxi = 0
	(n, x, m) = map(int, input().split())
	while m > 0:
		(l, r) = map(int, input().split())
		if l <= x <= r and flag == 0:
			mini = l
			maxi = r
			flag = 1
		elif (l <= mini <= r or l <= maxi <= r) and flag == 1:
			mini = min(mini, l)
			maxi = max(maxi, r)
		m -= 1
	if mini == 2 ** 29 - 1 or maxi == 0:
		print(1)
	else:
		print(maxi - mini + 1)
	t -= 1


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, x, m) = [int(zz) for zz in input().split()]
	lower = x
	upper = x
	for __ in range(m):
		(l, r) = [int(yy) for yy in input().split()]
		if l <= lower <= r:
			lower = min(lower, l)
		if l <= upper <= r:
			upper = max(upper, r)
	print(upper - lower + 1)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, x, m) = map(int, stdin.readline().split())
	var = [x, x]
	for _ in range(m):
		(a, b) = map(int, stdin.readline().split())
		if a <= var[0] <= b and var[1] > b:
			var = [a, var[1]]
		elif a <= var[1] <= b and var[0] < a:
			var = [var[0], b]
		elif a <= var[0] <= var[1] <= b:
			var = [a, b]
	print(var[1] - var[0] + 1)


q = int(input())
for i in range(q):
	(n, x, m) = map(int, input().split())
	l = x
	r = x
	for j in range(m):
		(nl, nr) = map(int, input().split())
		if nl > r or nr < l:
			continue
		if nr > r:
			r = nr
		if nl < l:
			l = nl
	print(r - l + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	x -= 1
	ans = 0
	lx = x
	rx = x
	for i in range(m):
		(l, r) = map(int, input().split())
		(l, r) = (l - 1, r - 1)
		if rx < l:
			continue
		elif lx <= l <= rx <= r:
			lx = lx
			rx = r
		elif lx <= l and r <= rx:
			lx = lx
			rx = rx
		elif l <= lx <= rx <= r:
			lx = l
			rx = r
		elif l <= lx <= r and r <= rx:
			lx = l
			rx = rx
		else:
			continue
	print(rx - lx + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(minv, maxv) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if not (r < minv or l > maxv):
			minv = min(l, minv)
			maxv = max(r, maxv)
	print(maxv - minv + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	lefts = -1
	rights = -1
	f = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if f == 0:
			if l <= x <= r:
				f = 1
				lefts = l
				rights = r
		else:
			if l < lefts and r >= lefts:
				lefts = l
			if r > rights and l <= rights:
				rights = r
	if lefts != -1 and rights != -1:
		print(rights - lefts + 1)
	else:
		print(1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def check(lft, rt, l, r):
	if l < lft and r < lft:
		return 0
	if l > rt:
		return 0
	return 1
for _ in range(int(input()) if True else 1):
	(n, x, m) = map(int, input().split())
	(lft, rt) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r or check(lft, rt, l, r):
			lft = min(l, lft)
			rt = max(r, rt)
	print(rt - lft + 1)


for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	arr = []
	small = x
	big = x
	for j in range(m):
		(l, r) = map(int, input().split())
		if big <= r and big >= l or (small <= r and small >= l):
			if l < small:
				small = l
			if r > big:
				big = r
	print(big - small + 1)


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for i in range(int(input())):
	(n, x, m) = map(int, input().split())
	q = 0
	k = [x, x]
	for i in range(m):
		(l, r) = map(int, input().split())
		if l < k[0] and r >= k[0]:
			k[0] = l
		if r > k[1] and l <= k[1]:
			k[1] = r
	print(k[1] - k[0] + 1)


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(n, x, m) = minput()
	(a, b) = (x, x)
	for i in range(m):
		(l, r) = minput()
		if max(l, a) <= min(r, b):
			(a, b) = (min(l, a), max(r, b))
	print(b - a + 1)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	(n, x, m) = rl()
	(lo, hi) = (x, x)
	for i in range(m):
		(l, r) = rl()
		if r >= lo:
			lo = min(lo, l)
		if l <= hi:
			hi = max(hi, r)
	print(hi - lo + 1)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


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


t = int(input())
for i in range(t):
	(n, x, m) = list(map(int, input().split(' ')))
	l = x
	r = x
	for j in range(m):
		(l_j, r_j) = list(map(int, input().split(' ')))
		if l_j <= l and r_j >= l:
			l = l_j
			r = max(r, r_j)
		elif r_j >= r and l_j <= r:
			r = r_j
			l = min(l, l_j)
	print(r - l + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().rstrip().split(' '))
	x = x - 1
	full_range = [x, x]
	for i in range(m):
		(l, r) = map(int, input().rstrip().split(' '))
		l -= 1
		r -= 1
		if full_range[0] in range(l, r + 1):
			full_range[0] = min(l, full_range[0])
			full_range[1] = max(r, full_range[1])
		elif full_range[1] in range(l, r + 1):
			full_range[0] = min(l, full_range[0])
			full_range[1] = max(r, full_range[1])
	print(full_range[1] - full_range[0] + 1)


def main():
	t = int(input())
	for _ in range(t):
		(n, x, m) = tuple(map(int, input().split()))
		l = x
		r = x
		for i in range(m):
			(p1, p2) = list(map(int, input().split()))
			if p2 >= l and (not p1 > r):
				l = min(l, p1)
			if p1 <= r and (not p2 < l):
				r = max(r, p2)
		print(r - l + 1)
main()


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		(n, x, m) = In()
		(lx, ux) = (x, x)
		for i in range(m):
			(l, r) = In()
			if ux < l or lx > r:
				continue
			lx = min(lx, l)
			ux = max(ux, r)
		print(ux - lx + 1)
main()


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict

def solve(arr, n):
	pass

def main():
	t = int(input())
	for _ in range(t):
		(n, x, m) = list(map(int, input().strip().split()))
		(st, ed) = (x, x)
		for _ in range(m):
			(l, r) = list(map(int, input().strip().split()))
			if st <= l and r <= ed:
				continue
			minn = max(l, st)
			maxx = min(r, ed)
			if l > maxx or r < minn:
				continue
			else:
				st = min(l, st)
				ed = max(r, ed)
		print(ed - st + 1)
main()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	s = x
	e = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= s and s <= b and (e >= a) and (e <= b):
			s = a
			e = b
		elif a <= s and s <= b and (b < e):
			s = a
		elif s < a and e >= a and (e <= b):
			e = b
	print(e - s + 1)


import sys
input = sys.stdin.readline
for cas in range(int(input())):
	(n, x, m) = map(int, input().split())
	(lft, rgt) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		(l, r) = (min(a, b), max(a, b))
		(teml, temr) = (max(l, lft), min(r, rgt))
		if teml <= temr:
			lft = min(l, lft)
			rgt = max(r, rgt)
	print(rgt - lft + 1)


t = int(input())
for i in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	(start, end) = (x, x)
	for j in range(m):
		(l, r) = [int(x) for x in input().split()]
		if r >= start >= l or r >= end >= l:
			if start > l:
				start = l
			if end < r:
				end = r
	print(end - start + 1)


t = int(input())
for i in range(t):
	(n, x, m) = [int(k) for k in input().split()]
	w = []
	for j in range(m):
		w.append([int(k) for k in input().split()])
	w = w[::-1]
	(l, r) = (-1, -1)
	while m > 0:
		c = w.pop()
		if l == -1:
			if c[0] <= x <= c[1]:
				(l, r) = (c[0], c[1])
		else:
			if c[0] <= l <= c[1]:
				l = c[0]
			if c[0] <= r <= c[1]:
				r = c[1]
		m -= 1
	print(r - l + 1)


def intersect(l0, r0, l1, r1):
	return (l1 - r0) * (r1 - l0) <= 0

def process():
	[n, x, m] = list(map(int, input().split(' ')))
	(left, right) = (x, x)
	for _ in range(m):
		[l, r] = list(map(int, input().split(' ')))
		if intersect(left, right, l, r):
			left = min(left, l)
			right = max(right, r)
	print(right - left + 1)
t = int(input())
for _ in range(t):
	process()


for t in range(int(input())):
	(n, x, m) = (int(i) for i in input().split())
	ints = []
	for i in range(m):
		ints.append([int(i) for i in input().split()])
	strt = 0
	end = 0
	curb = x
	curf = x
	curf0 = -1
	curb0 = -1
	curf0 = curf
	curb0 = curb
	for i in range(m):
		if ints[i][0] <= curb and ints[i][1] >= curb:
			curb = ints[i][1]
		if ints[i][0] <= curf and ints[i][1] >= curf:
			curf = ints[i][0]
	print(-curf + curb + 1)


t = int(input())
while t:
	t -= 1
	(n, x, m) = [int(s) for s in input().split()]
	mat = []
	for i in range(m):
		mat.append([int(s) for s in input().split()])
	cur_range = [x, x]
	for i in range(m):
		cur_l = mat[i][0]
		cur_r = mat[i][1]
		if cur_range[0] >= cur_l and cur_range[0] <= cur_r or (cur_range[1] >= cur_l and cur_range[1] <= cur_r):
			cur_range[0] = min(cur_l, cur_range[0])
			cur_range[1] = max(cur_r, cur_range[1])
		else:
			pass
	ans = cur_range[1] - cur_range[0] + 1
	print(ans)


tests = int(input())
for _ in range(tests):
	(n, x, m) = map(int, input().split())
	otr = [x, x]
	sp = []
	for i in range(m):
		(l, r) = map(int, input().split())
		if otr[0] <= r <= otr[1] or otr[0] <= l <= otr[1] or (l <= otr[0] and r >= otr[1]):
			otr[0] = min(otr[0], l)
			otr[1] = max(otr[1], r)
	print(otr[1] - otr[0] + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	a = [[int(x) for x in input().split()] for i in range(m)]
	c = 0
	b = []
	for i in a:
		if b != []:
			m1 = min(b)
			m2 = max(b)
		if x in range(i[0], i[1] + 1) or (b != [] and (m1 <= i[1] <= m2 or m1 <= i[0] <= m2)):
			if i[0] not in b:
				b.append(i[0])
			if i[1] not in b:
				b.append(i[1])
	if b == []:
		print('1')
	else:
		print(max(b) - min(b) + 1)


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


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, x, m, a):
	x1 = n
	x2 = -1
	for i in range(0, m):
		if x >= a[i][0] and x <= a[i][1]:
			x1 = min(x1, a[i][0])
			x2 = max(x2, a[i][1])
		elif x2 > 0:
			if x1 <= a[i][0] <= x2 or x1 <= a[i][1] <= x2:
				x1 = min(x1, a[i][0])
				x2 = max(x2, a[i][1])
	if x2 < 0:
		return 1
	return x2 - x1 + 1
for t in range(0, tests):
	(n, x, m) = list(map(int, readline().rstrip('\n').split(' ')))
	a = []
	for i in range(0, m):
		a.append(list(map(int, readline().split(' '))))
	print(solve(n, x, m, a))


t = int(input())
for f in range(t):
	(n, x, m) = map(int, input().split())
	ans = [x, x]
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= ans[1] and r >= ans[0]:
			ans[0] = min(l, ans[0])
			ans[1] = max(r, ans[1])
	print(ans[1] - ans[0] + 1)


import math
import sys
from itertools import permutations
from collections import defaultdict
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	ans = []
	for j in range(m):
		(l, r) = map(int, input().split())
		if len(ans) == 0:
			if l <= x and r >= x:
				ans.append([l, r])
		else:
			for arr in ans:
				if not (arr[1] < l or r < arr[0]):
					ans.append([l, r])
					break
	ans.sort()
	fin = 0
	start = 0
	end = 0
	for arr in ans:
		if arr[0] > end:
			start = arr[0]
			end = arr[1]
			fin += end - start + 1
		elif arr[0] <= end and arr[1] <= end:
			pass
		elif arr[0] <= end and arr[1] > end:
			fin += arr[1] - end
			end = arr[1]
	print(max(1, fin))


MAX = float('inf')
MIN = -float('inf')
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	ans = [MAX, MIN]
	s = [MAX, MIN]
	x = [x, x]
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= x[0] <= b or a <= x[1] <= b:
			ans[0] = min(a, ans[0])
			ans[1] = max(b, ans[1])
			x = ans[:]
	if ans == s:
		print(1)
	else:
		print(ans[1] - ans[0] + 1)


import sys
import math
from collections import Counter
from operator import itemgetter
import queue

def IO():
	sys.stdin = open('pyinput.txt', 'r')
	sys.stdout = open('pyoutput.txt', 'w')

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

def LCM(a, b):
	return a * (b // GCD(a, b))

def scan(TYPE_1, TYPE_2=0):
	if TYPE_1 == int:
		return map(int, sys.stdin.readline().strip().split())
	elif TYPE_1 == float:
		return map(float, sys.stdin.readline().strip().split())
	elif TYPE_1 == list and TYPE_2 == float:
		return list(map(float, sys.stdin.readline().strip().split()))
	elif TYPE_1 == list and TYPE_2 == int:
		return list(map(int, ('0 ' + sys.stdin.readline()).strip().split()))
	elif TYPE_1 == str:
		return sys.stdin.readline().strip()
	else:
		print('ERROR!!!!')

def main():
	t = int(input())
	while t > 0:
		(n, x, m) = scan(int)
		l = x
		r = x
		while m > 0:
			(a, b) = scan(int)
			if l <= a <= r or l <= b <= r or a <= l <= b or (a <= r <= b):
				l = min(a, l)
				r = max(b, r)
			m -= 1
		print(r - l + 1)
		t -= 1
main()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = [x] * 2
	for i in range(m):
		(l, r) = map(int, input().split())
		if a[0] <= l <= a[1] and r > a[1]:
			a[1] = r
		if a[0] <= r <= a[1] and l <= a[0]:
			a[0] = l
		if r >= a[1] and l <= a[0]:
			a[0] = l
			a[1] = r
	print(a[1] - a[0] + 1)


t = int(input())
rez = []
for i in range(t):
	l = []
	r = []
	A = input().split(' ')
	n = int(A[0])
	x = int(A[1])
	m = int(A[2])
	index = m
	rezu = 1
	for j in range(m):
		B = input().split()
		r.append(int(B[1]))
		l.append(int(B[0]))
	for j in range(m):
		if x >= l[j] and x <= r[j]:
			rezu += r[j] - l[j]
			ll = l[j]
			rr = r[j]
			index = j
			break
	while index < m:
		if r[index] > rr and l[index] <= rr:
			rezu += r[index] - rr
			if l[index] < ll:
				rezu += ll - l[index]
				ll = l[index]
			rr = r[index]
		elif l[index] < ll and r[index] >= ll:
			rezu += ll - l[index]
			ll = l[index]
			if r[index] > rr:
				rezu += r[index] - rr
				rr = r[index]
		index += 1
	rez.append(rezu)
for i in range(len(rez)):
	print(rez[i])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	ans = 1
	(pl, pr) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= pl <= pr <= r:
			ans = r - l + 1
			pl = l
			pr = r
		elif l <= pl <= r:
			ans += pl - l
			pl = l
		elif l <= pr <= r:
			ans += r - pr
			pr = r
	print(ans)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	d = dict()
	p = 0
	mi = x
	ma = x
	for j in range(m):
		(l, r) = map(int, input().split())
		if mi in range(l, r + 1):
			mi = min(mi, l)
		if ma in range(l, r + 1):
			ma = max(ma, r)
	print(ma - mi + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(l, r) = (-1, -1)
	for i in range(m):
		(tl, tr) = map(int, input().split())
		if l == -1:
			if x in range(tl, tr + 1):
				(l, r) = (tl, tr)
		elif tl in range(l, r + 1) or tr in range(l, r + 1) or l in range(tl, tr + 1) or (r in range(tl, tr + 1)):
			l = min(l, tl)
			r = max(r, tr)
	print(r - l + 1)


t = int(input())
while t > 0:
	(n, x, m) = map(int, input().split())
	(lo, hi) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if lo <= r and hi >= r or (l <= hi and r >= hi):
			lo = min(lo, l)
			hi = max(hi, r)
	print(hi - lo + 1)
	t -= 1


import math
from decimal import *
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	pos = []
	(p1, p2) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		pos.append([a, b])
	for i in range(m):
		if pos[i][1] >= p1:
			p1 = min(pos[i][0], p1)
		if p2 >= pos[i][0] and p2 <= pos[i][1]:
			p2 = max(pos[i][1], p2)
	print(p2 - p1 + 1)


tll = int(input())
while tll > 0:
	tll -= 1
	(n, x, m) = map(int, input().split())
	(l, r) = (x, x)
	al = l
	ar = r
	for i in range(m):
		(li, ri) = map(int, input().split())
		if min(r, ri) - max(li, l) >= 0:
			al = min(l, li, al)
			ar = max(ar, ri, r)
			(l, r) = (al, ar)
	print(ar - al + 1)


t = int(input())
while t:
	t += -1
	(n, x, m) = map(int, input().split())
	(lo, hi) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if r < lo or l > hi:
			continue
		if l < lo:
			lo = l
		if r > hi:
			hi = r
	print(hi - lo + 1)


import sys
TEST = 0
if TEST == 1:
	input_file = open('inputB.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))

def read_str():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return in1
tests = read_int()
for test in range(tests):
	(n, x, m) = read_ints()
	(L, R) = (x, x)
	for j in range(m):
		(l, r) = read_ints()
		if l <= L <= r or l <= R <= r:
			L = min(l, L)
			R = max(r, R)
	ans = R - L + 1
	print(ans)


for t in range(int(input())):
	(n, x, m) = map(int, input().split())
	le = -1
	ri = -1
	flag = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if flag != 0:
			if l < le and r >= le:
				le = l
			if r > ri and l <= ri:
				ri = r
		elif l <= x <= r:
			flag = 1
			le = l
			ri = r
	if le != -1 and ri != -1:
		print(ri - le + 1)
	else:
		print(1)


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


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	depend = []
	for k in range(m):
		depend.sort()
		(l, r) = map(int, input().split())
		if l <= x and r >= x:
			depend.append([l, r])
			continue
		rr = len(depend)
		for i in range(rr):
			if depend[i][0] <= l and depend[i][1] >= l or (depend[i][0] <= r and depend[i][1] >= r):
				depend.append([l, r])
				break
	depend.sort()
	if len(depend) == 0:
		print(1)
		continue
	start = depend[0][0]
	end = depend[0][1]
	ans = end - start + 1
	for i in range(1, len(depend)):
		if depend[i][0] != start:
			if depend[i][0] <= end:
				if depend[i][1] >= end:
					sub = end - depend[i][0] + 1
					ans = ans + (depend[i][1] - depend[i][0] + 1) - sub
					end = depend[i][1]
				else:
					continue
			else:
				ans = ans + (depend[i][1] - depend[i][0] + 1)
				start = depend[i][0]
				end = depend[i][1]
		else:
			sub = depend[i][1] - end
			ans = ans - (end - start + 1)
			ans = ans + (depend[i][1] - depend[i][0] + 1)
			end = depend[i][1]
	print(ans)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(R, L) = (x, x)
	c = 0
	for __ in range(m):
		(l, r) = map(int, input().split())
		if c:
			if l <= R:
				R = max(r, R)
			if r >= L:
				L = min(l, L)
			continue
		if l <= x <= r:
			c = 1
			(R, L) = (r, l)
	print(R - L + 1)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(z, x, v) = (b, b, 1)
	for _ in range(c):
		(q, w) = map(int, input().split())
		if z >= q and x <= w:
			v += z - q + (w - x)
			(z, x) = (q, w)
		elif z >= q and z <= w:
			v += z - q
			z = q
		elif x >= q and x <= w:
			v += w - x
			x = w
	print(v)


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


import sys
import collections
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, x, m) = list(map(int, sys.stdin.readline().strip().split(' ')))
	queries = []
	for q in range(m):
		queries.append(list(map(int, sys.stdin.readline().strip().split(' '))))
	r = [x, x]
	for q in queries:
		start = q[0]
		end = q[1]
		if end < r[0] or r[1] < start:
			continue
		r = [min(r[0], start), max(end, r[1])]
	print(r[1] - r[0] + 1)


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		flag = 0
		for i in range(m):
			(l, r) = map(int, input().split())
			if flag == 0:
				if x >= l and x <= r:
					flag = 1
					p = l
					q = r
			else:
				if r >= p:
					p = min(p, l)
				if l <= q:
					q = max(q, r)
		if flag == 0:
			print(1)
		else:
			print(q - p + 1)
solution()


def prog():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		indexes = [list(map(int, input().split())) for i in range(m)]
		left = x
		right = x
		for swap in indexes:
			(a, b) = swap
			if not (right < a or left > b):
				right = max(b, right)
				left = min(a, left)
		print(right - left + 1)
prog()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, x, m) = inputnums()
	mn = x
	mx = x
	for i in range(m):
		(u, v) = inputnums()
		if u <= mx and v >= mn:
			mn = min(u, mn)
			mx = max(v, mx)
	print(mx - mn + 1)


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heapify, heappop
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def check(a, b, c, d):
	if (a == c or a == d) or (b == c or b == d):
		return True
	elif a <= c and c <= b or (a <= d and d <= b):
		return True
	elif c <= a and a <= d or (c <= b and b <= d):
		return True
	return False
t = I()
right = 0
left = 10 ** 10
for _ in range(t):
	(n, x, m) = M()
	f = 0
	p = 10 ** 10
	q = -1
	d = []
	for i in range(m):
		(a, b) = M()
		d.append((a, b))
		if (x >= a and x <= b or (x == a or x == b)) and f == 0:
			key = i
			p = a
			q = b
			f = 1
	if p == 10 ** 10 and q == -1:
		print(1)
	else:
		for j in range(key, m):
			if check(p, q, d[j][0], d[j][1]):
				p = min(p, d[j][0])
				q = max(q, d[j][1])
		print(q - p + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	arr = [list(map(int, input().split())) for i in range(m)]
	temp = [[x, x]]
	ans = 0
	for i in range(m):
		for j in temp:
			if arr[i][0] <= j[1] and arr[i][1] >= j[0]:
				temp.append(arr[i])
				break
	temp1 = sorted(temp, key=lambda x: x[0])
	start = temp1[0][0]
	end = temp1[0][1]
	for i in range(1, len(temp1)):
		if end >= temp1[i][0]:
			end = max(end, temp1[i][1])
		else:
			ans += end - start + 1
			start = temp1[i][0]
			end = temp1[i][1]
	ans += end - start + 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = ain()
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def main():
	for _ in range(iin()):
		(n, x, m) = ain()
		l = x
		r = x
		k = 1
		for i in range(m):
			(li, ri) = ain()
			if li > r or ri < l:
				continue
			else:
				if li < l:
					k += l - li
				if ri > r:
					k += ri - r
				l = min(li, l)
				r = max(ri, r)
		print(k)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(left, right) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= left <= right <= r:
			left = l
			right = r
		elif left <= l <= right <= r:
			right = r
		elif l <= left <= r <= right:
			left = l
		else:
			continue
	print(right - left + 1)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, x, m) = map(int, input().split())
	i = x - 1
	j = x - 1
	for ii in range(m):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		if u <= i and v >= i or (u <= j and v >= j):
			i = min(i, u)
			j = max(j, v)
	print(j - i + 1)
	t -= 1


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def foo():
	(n, x, m) = invr()
	(ll, rr) = (x, x)
	for i in range(m):
		(l1, r1) = invr()
		if r1 < ll or rr < l1:
			continue
		else:
			ll = min(ll, l1)
			rr = max(rr, r1)
	ans = rr - ll + 1
	print(ans)
t = inp()
for i in range(t):
	foo()


def f(al, ii):
	st = False
	cr = 0
	for i in al:
		i.sort()
		if not st and (ii < i[0] or ii > i[1]):
			continue
		else:
			st = True
			if cr == 0:
				cr = i
			tpp = [cr, i]
			tpp.sort()
			if tpp[-1][0] <= tpp[0][1]:
				tp = merge(tpp)
				if len(tp) == 1:
					tp[0].sort()
					cr = tp[0]
	return cr

def merge(intervals):
	intervals.sort(key=lambda x: x[0])
	merged = []
	for interval in intervals:
		if not merged or merged[-1][1] < interval[0]:
			merged.append(interval)
		else:
			merged[-1][1] = max(merged[-1][1], interval[1])
	return merged
for tc in range(int(input())):
	al = list(map(int, input().split()))
	x = al[1]
	m = al[2]
	al = []
	for j in range(m):
		al.append(list(map(int, input().split())))
	tt = f(al, x)
	if tt == 0:
		print(1)
	else:
		print(tt[1] - tt[0] + 1)


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


T = int(input())
for t in range(T):
	(n, x, m) = list(map(int, input().split()))
	lx = x
	rx = x
	for i in range(m):
		(li, ri) = list(map(int, input().split()))
		if lx <= ri and lx >= li:
			lx = min(lx, li)
			rx = max(ri, rx)
		if rx >= li and rx <= ri:
			lx = min(lx, li)
			rx = max(ri, rx)
	print(rx - lx + 1)


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


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	L = R = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if l <= L and r >= R:
			R = r
			L = l
		elif r > R and l <= R:
			R = r
		elif l < L and r >= L:
			L = l
	print(R - L + 1)


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	jbeca = 0
	move = 1
	for O_ in range(m):
		(l, r) = map(int, input().split())
		jbeca += 1
		if l <= x and r >= x:
			move = r - l + 1
			break
	for O_ in range(m - jbeca):
		(p1, p2) = map(int, input().split())
		if p1 <= l and p2 >= r:
			move = p2 - p1 + 1
			l = p1
			r = p2
		elif p1 >= l and p1 <= r and (p2 >= r):
			move = p2 - l + 1
			r = p2
		elif p1 <= l and p2 <= r and (p2 >= l):
			move = r - p1 + 1
			l = p1
	print(move)


for test_i in range(int(input())):
	(n, x, m) = map(int, input().split())
	(ans_l, ans_r) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l < ans_l and r >= ans_l:
			ans_l = l
		if r > ans_r and l <= ans_r:
			ans_r = r
	print(ans_r - ans_l + 1)


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	ans = 0
	flag = 0
	l1 = 0
	r1 = 0
	for j in range(m):
		(l, r) = map(int, input().split())
		if x >= l and x <= r and (flag == 0):
			l1 = l
			r1 = r
			flag = 1
		elif l1 <= r and l1 >= l or ((r1 <= r and r1 >= l) and flag == 1):
			l1 = min(l, l1)
			r1 = max(r, r1)
	ans += r1 - l1 + 1
	print(ans)


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


def update(cur, nxt):
	if nxt[0] <= cur[0] <= nxt[1] or nxt[0] <= cur[1] <= nxt[1]:
		return [min(cur[0], nxt[0]), max(cur[1], nxt[1])]
	else:
		return cur
t = int(input())
for i in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	cur = [x, x]
	for j in range(m):
		nxt = [int(x) for x in input().split()]
		cur = update(cur, nxt)
	print(cur[1] - cur[0] + 1)


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue
sys.setrecursionlimit(200000)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for i in range(t):
	(n, x, m) = rinput()
	query = []
	for i in range(m):
		(u, v) = rinput()
		query.append([u, v])

	def merge(a, b):
		(s1, s2) = (min(a[0], b[0]), max(a[0], b[0]))
		(e1, e2) = (min(a[1], b[1]), max(a[1], b[1]))
		if s2 > e1:
			return []
		return [s1, e2]
	tup = []
	ans = 0
	for i in range(m):
		q = query[i]
		if tup != []:
			mm = merge(tup, q)
			if mm != []:
				tup = mm
		if tup == [] and q[0] <= x <= q[1]:
			tup = q
	print(tup[1] - tup[0] + 1 if tup != [] else 1)


import sys
import collections as cc
import bisect as bi
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, x, m) = I()
	ans = 1
	actx = 10 ** 9 + 10
	acty = -10 ** 9 + 10
	f = 0
	for i in range(m):
		(l, r) = I()
		if not f and x >= l and (x <= r):
			ans += abs(l - r)
			actx = l
			acty = r
			f = 1
		elif f:
			if l >= actx and r <= acty:
				continue
			elif l < actx and r > acty:
				ans += abs(l - actx)
				ans += abs(r - acty)
				acty = r
				actx = l
			elif l < actx and r >= actx and (r <= acty):
				ans += abs(l - actx)
				actx = l
			elif r > acty and l >= actx and (l <= acty):
				ans += abs(r - acty)
				acty = r
	print(ans)


def problem1():
	(a, b) = list(map(int, input().split()))
	if b > a:
		b = b + a
		a = b - a
		b = b - a
	if a * b < 2:
		print(0)
	elif a >= 2 * b:
		print(b)
	else:
		print(a - b + 2 * (2 * b - a) // 3)

def problem2():
	(n, x, m) = list(map(int, input().split()))
	a = x
	b = x
	for _ in range(m):
		(l, r) = list(map(int, input().split()))
		if l < a and r >= a:
			a = l
		if r > b and l <= b:
			b = r
	print(b - a + 1)
cases = int(input())
for _ in range(cases):
	problem2()


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def preorder_postorder(root, paths, parent, left, level):
	l = 0
	queue = [root]
	while queue != []:
		node = queue[-1]
		flag = 0
		for i in paths[node]:
			if i != parent[node] and level[i] == sys.maxsize:
				parent[i] = node
				level[i] = level[node] + 1
				flag = 1
				queue.append(i)
		if flag == 0:
			left[parent[node]] += 1 + left[node]
			queue.pop()
	return [parent, left, level]

def nCr(n, r, p):
	if r == 0:
		return 1
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def f_exp(p, k0, k1, l):
	ans = 1
	k = k0 - k1
	while k != 0:
		if k % 2 == 0:
			k = k // 2
			p = p * p
		else:
			ans = ans * p
			k = (k - 1) // 2
			p = p * p
		if ans > l:
			ans = -1
			break
	return ans

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		[n, x, m] = inlt()
		l = x
		r = x
		for i in range(m):
			[c_l, c_r] = inlt()
			if c_l <= r and c_l >= l or (c_r >= l and c_l <= r):
				l = min(l, c_l)
				r = max(r, c_r)
		print(r - l + 1)
main()


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, x, m) = map(int, stdin.readline().split())
	minn = x
	maxx = x
	for i in range(m):
		(l, r) = map(int, stdin.readline().split())
		if r >= minn and l <= minn:
			maxx = max(maxx, r)
			minn = min(minn, l)
		elif r >= maxx and l <= maxx:
			maxx = max(maxx, r)
			minn = min(minn, l)
	print(maxx - minn + 1)


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


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	l = x
	r = x
	for _ in range(m):
		(w, z) = map(int, input().split())
		if w <= l <= z or w <= r <= z:
			if w < l:
				l = w
			if z > r:
				r = z
	print(r - l + 1)


import sys
max_int = 1000000001
min_int = -max_int
t = int(sys.stdin.readline())
for _ in range(t):
	(n, x, m) = map(int, sys.stdin.readline().split())
	lx = rx = x
	for _m in range(m):
		(l, r) = map(int, sys.stdin.readline().split())
		if l > rx or r < lx:
			continue
		lx = min(l, lx)
		rx = max(r, rx)
	print(rx - lx + 1)


T = int(input())
for t in range(T):
	(n, x, m) = map(int, input().split())
	(L, R) = map(int, input().split())
	for _ in range(1, m):
		(l, r) = list(map(int, input().split()))
		if x >= L and x <= R:
			if l >= L and l <= R:
				if r > R:
					R = r
			elif r <= R and r >= L:
				if l < L:
					L = l
			elif l < L and r > R:
				R = r
				L = l
		elif x >= l and x <= r:
			L = l
			R = r
	if x >= L and x <= R:
		print(R - L + 1)
	else:
		print(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()


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


amount_test_cases = int(input())

def is_in_range(left, right, target: list):
	if left <= target[0] <= right or left <= target[1] <= right:
		return True
	return False

def print_total_positions(array_lenght, initial_range, operations):
	for range in operations:
		left = int(range[0])
		right = int(range[1])
		if is_in_range(left, right, initial_range):
			initial_range[0] = min(left, initial_range[0])
			initial_range[1] = max(right, initial_range[1])
	print(initial_range[1] - initial_range[0] + 1)
for _ in range(amount_test_cases):
	operations = []
	(array_lenght, index, amount_operations) = input().split(' ')
	for _ in range(int(amount_operations)):
		operations.append(input().split(' '))
	print_total_positions(array_lenght, [int(index), int(index)], operations)


import sys
t = int(sys.stdin.readline())
while t:
	(n, a, m) = map(int, sys.stdin.readline().split())
	listt = []
	for _ in range(m):
		(l, r) = map(int, sys.stdin.readline().split())
		listt.append((l, r))
	stack = []
	found = False
	for (x, y) in listt:
		if not found:
			if a in range(x, y + 1):
				found = True
				(rangex, rangey) = (x, y)
		else:
			if x in range(rangex, rangey + 1):
				rangey = max(rangey, y)
			if y in range(rangex, rangey + 1):
				rangex = min(x, rangex)
			if rangex in range(x, y + 1) and rangey in range(x, y + 1):
				rangex = min(x, rangex)
				rangey = max(rangey, y)
	if found:
		print(rangey - rangex + 1)
	else:
		print(1)
	t -= 1


for _ in ' ' * int(input()):
	(a, b, c) = map(int, input().split())
	(b1, b2) = (b, b)
	for i in range(c):
		(d, e) = map(int, input().split())
		if e >= b1 and b2 >= d:
			b1 = min(b1, d, e)
			b2 = max(b2, e, d)
	print(b2 - b1 + 1)


I = lambda : map(int, input().split())
for _ in range(next(I())):
	(n, x, m) = I()
	a2 = a1 = x
	for i in range(m):
		(l, r) = I()
		if l <= a2 <= r or l <= a1 <= r:
			a1 = min(a1, l)
			a2 = max(a2, r)
	print(abs(a1 - a2) + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	arr = [[0, 0] for i in range(m)]
	for i in range(m):
		arr[i] = list(map(int, input().split()))
	l = x
	r = x
	for (a, b) in arr:
		if a <= l and l <= b:
			l = a
		if a <= r and r <= b:
			r = b
	print(r - l + 1)


t = int(input())
while t:
	t -= 1
	(n, x, q) = map(int, input().split(' '))
	l = x
	r = x
	while q:
		q -= 1
		(a, b) = map(int, input().split(' '))
		if r < a or l > b:
			continue
		l = min(l, a)
		r = max(r, b)
	print(r - l + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	xr = [x, x]
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		if xr[0] >= l and xr[0] <= r or (xr[1] >= l and xr[1] <= r):
			xr = [min(l, xr[0]), max(r, xr[1])]
	print(xr[1] - xr[0] + 1)


T = int(input())
for _ in range(0, T):
	(n, x, m) = map(int, input().split())
	L = []
	for i in range(0, m):
		(l, r) = map(int, input().split())
		L.append((l, r))
	ans = 0
	lf = x
	rg = x
	for i in range(0, len(L)):
		if L[i][1] < lf or L[i][0] > rg:
			c = 1
		else:
			lf = min(lf, L[i][0])
			rg = max(rg, L[i][1])
	print(rg - lf + 1)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def solve():
	(n, x, m) = map(int, input().split())
	pos = []
	(l1, r1) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if l > r1 or r < l1:
			continue
		else:
			(l1, r1) = (min(l, l1), max(r, r1))
	print(r1 - l1 + 1)
for _ in range(int(input())):
	solve()


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for _ in range(INT()):
	(n, x, m) = MAP()
	(l, r) = (x, x)
	for i in range(m):
		(a, b) = MAP()
		if a > r or l > b:
			continue
		else:
			l = min(l, a)
			r = max(r, b)
	print(r - l + 1)


import sys
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	ba = x
	for j in range(m):
		(a, b) = map(int, input().split())
		if a <= x:
			if b >= x and b <= ba:
				x = a
			elif b >= ba:
				x = a
				ba = b
		elif a >= x and a <= ba:
			if b >= ba:
				ba = b
	print(1 + ba - x)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	lm = x
	rm = x
	for op in range(m):
		(l, r) = map(int, input().split())
		if l <= lm and r >= lm:
			lm = l
		if r >= rm and l <= rm:
			rm = r
	print(rm - lm + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	p = q = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if q < l:
			continue
		elif r < p:
			continue
		p = min(l, p)
		q = max(q, r)
	print(q - p + 1)


def answer(n, x, m, A):
	mini = 0
	maxi = 0
	flag = 0
	for i in range(0, m):
		if A[i][0] <= x <= A[i][1] and flag == 0:
			mini = A[i][0]
			maxi = A[i][1]
			flag = 1
		elif flag == 1:
			if A[i][0] < mini and A[i][1] >= mini:
				mini = A[i][0]
				maxi = max(maxi, A[i][1])
			if A[i][0] <= maxi and A[i][1] > maxi:
				maxi = A[i][1]
				mini = min(mini, A[i][0])
	return maxi - mini + 1
t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	l = []
	for i in range(m):
		l.append(list(map(int, input().split())))
	print(answer(n, x, m, l))


def first_element(_range):
	return _range[0]

def combine_if_possible(full_range, new_range):
	ranges = [full_range, new_range]
	ranges.sort(key=first_element)
	(range1, range2) = ranges
	if range1[1] >= range2[0]:
		return (range1[0], max(range1[1], range2[1]))
	else:
		return full_range

def solve():
	(n, x, m) = map(int, input().strip().split())
	full_range = (x, x)
	for i in range(m):
		new_range = tuple(map(int, input().strip().split()))
		full_range = combine_if_possible(full_range, new_range)
	print(full_range[1] - full_range[0] + 1)
t = int(input().strip())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
for T in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	d = {}
	d[x] = 1
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		for j in d:
			if j >= l and j <= r:
				d[l] = 1
				d[r] = 1
				break
	key = list(d.keys())
	key.sort()
	print(key[-1] - key[0] + 1)


import math
m = 1000000007

def fact(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans % m * (i % m) % m
	return ans

def power_2(n):
	ans = 1
	for i in range(n):
		ans = ans % m * 2 % m
	return ans
for t in range(int(input())):
	(n, x, m) = map(int, input().split())
	(i, j) = (x, x)
	for z in range(m):
		(l, r) = map(int, input().split())
		if i >= l and i <= r or (j >= l and j <= r):
			if l < i:
				i = l
			if r > j:
				j = r
	print(j - i + 1)


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


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		bl = False
		a = -1
		b = -1
		for i in range(m):
			(l, r) = map(int, input().split())
			if bl == False:
				if x >= l and x <= r:
					a = l
					b = r
					bl = True
			elif l >= a and l <= b or (r <= b and r >= a) or (l <= a and r >= b):
				a = min(l, a)
				b = max(b, r)
		print(b - a + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	start = x
	end = x
	for i in range(m):
		(left, right) = map(int, input().split())
		if right < start or left > end:
			continue
		else:
			start = min(left, start)
			end = max(right, end)
	print(end - start + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(l1, l2) = (x, x)
	for _ in range(m):
		(p, q) = map(int, input().split())
		if p < l1 <= q:
			l1 = p
		if q > l2 >= p:
			l2 = q
	print(l2 - l1 + 1)


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


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def bo(i):
	return ord(i) - ord('a')
from copy import *
from bisect import *
from itertools import permutations
t = int(input())
while t > 0:
	t -= 1
	(n, k, m) = mi()
	mxl = k
	mxr = k
	for i in range(m):
		(x, y) = mi()
		if x <= mxl <= y:
			mxl = min(mxl, x)
		if x <= mxr <= y:
			mxr = max(mxr, y)
	print(mxr - mxl + 1)


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


N = int(input())
for _ in range(N):
	(a, b, c) = map(int, input().split())
	sim = 0
	for i in range(c):
		(x, y) = map(int, input().split())
		if sim:
			if x <= a and a <= y:
				a = x
			if b <= y and x <= b:
				b = y
			continue
		if x <= b and b <= y:
			sim = 1
			a = x
			b = y
	if sim:
		print(b - a + 1)
	else:
		print(1)


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		(n, x, m) = MP()
		(fg, mn, mx) = (0, 0, 0)
		for i in range(m):
			(a, b) = MP()
			if fg:
				if b >= mn:
					mn = min(a, mn)
				if a <= mx:
					mx = max(b, mx)
			elif a <= x and b >= x:
				mn = a
				mx = b
				fg = 1
		if mn > mx:
			print(1)
		else:
			print(mx - mn + 1)
solve()


for case in range(int(input())):
	flag = True
	(n, x, m) = [int(x) for x in input().split()]
	L = x
	R = x
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		if l <= R and r >= L:
			L = min(L, l)
			R = max(R, r)
	print(R - L + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = [int(s) for s in input().split(' ')]
	(k_l, k_r) = (x, x)
	set_k = 1
	for i in range(m):
		(l, r) = [int(s) for s in input().split(' ')]
		if k_l <= l and k_r >= l or (k_l <= r and k_r >= r) or (k_l >= l and k_r <= r):
			set_k = max(r, k_r) - min(l, k_l) + 1
			k_l = min(l, k_l)
			k_r = max(r, k_r)
	print(set_k)


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


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	(n, x, m) = sep()
	left = x
	right = x
	for i in range(0, m):
		(l, r) = sep()
		if l > right or r < left:
			continue
		else:
			left = min(left, l)
			right = max(right, r)
	print(right - left + 1)
testcase(int(inp()))


def main():
	t = int(input())
	test_case_num = 1
	while test_case_num <= t:
		(n, x, m) = map(int, input().split())
		interval = (x, x)
		for q in range(m):
			(li, ri) = map(int, input().split())
			if max(interval[0], li) <= min(interval[1], ri):
				interval = (min(interval[0], li), max(interval[1], ri))
		print(interval[1] - interval[0] + 1)
		test_case_num += 1
main()


T = int(input())
for _ in range(T):
	(n, x, m) = map(int, input().split())
	arr = []
	for i in range(m):
		arr.append(list(map(int, input().split())))
	l = x
	r = x
	for i in arr:
		if i[0] <= l <= i[1]:
			l = i[0]
		if i[0] <= r <= i[1]:
			r = i[1]
	print(r - l + 1)


import sys, math
import io, os

def data():
	return sys.stdin.buffer.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	(n, x, m) = mdata()
	s = e = x
	for i in range(m):
		(a, b) = mdata()
		if s <= a <= e or s <= b <= e or a <= s <= b:
			s = min(a, s)
			e = max(b, e)
	out(e - s + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	c = [0, 0]
	p = 0
	for i in range(m):
		(a, b) = map(int, input().split())
		if c == [0, 0]:
			if b >= x >= a:
				c = [a, b]
				p = c[1] + 1 - c[0]
		elif a <= c[0] and b >= c[1]:
			c = [a, b]
			p = c[1] + 1 - c[0]
		elif a <= c[0] and c[0] < b <= c[1]:
			c = [a, c[1]]
			p = c[1] + 1 - c[0]
		elif c[1] > a >= c[0] and b >= c[1]:
			c = [c[0], b]
			p = c[1] + 1 - c[0]
		elif a <= c[0] and b == c[0]:
			c = [a, c[1]]
			p = c[1] + 1 - c[0]
		elif a == c[1] and b >= c[1]:
			c = [c[0], b]
			p = c[1] + 1 - c[0]
	print(max(p, 1))


def main():
	(n, x, m) = [int(a) for a in input().split()]
	lrs = []
	l_s = int(1000000000.0 + 5)
	r_s = -99
	for mi in range(m):
		(li, ri) = [int(a) for a in input().split()]
		lrs.append([li, ri])
	ans = 1
	for mi in range(m):
		if lrs[mi][0] <= x and lrs[mi][1] >= x:
			l_s = min(lrs[mi][0], l_s)
			r_s = max(lrs[mi][1], r_s)
		if lrs[mi][1] <= r_s and lrs[mi][1] >= l_s:
			l_s = min(lrs[mi][0], l_s)
			r_s = max(lrs[mi][1], r_s)
		elif lrs[mi][0] <= r_s and lrs[mi][0] >= l_s:
			l_s = min(lrs[mi][0], l_s)
			r_s = max(lrs[mi][1], r_s)
		else:
			pass
	ans = max(ans, r_s - l_s + 1)
	print(ans)
t = int(input())
for _ in range(t):
	main()


q = int(input())
for z in range(q):
	(n, x, m) = map(int, input().split(' '))
	(l, r) = (x, x)
	for e in range(m):
		(a, b) = map(int, input().split(' '))
		if l >= a and l <= b or (r >= a and r <= b):
			if l > a:
				l = a
			if b > r:
				r = b
	print(r - l + 1)


def solve1(a, b):
	a1 = a // 2
	b1 = b // 2
	if a == 0 or b == 0:
		return 0
	if a == 1 or b == 1:
		return 1
	if a == b:
		return a // 2
	res = -1
	if a < b:
		res = min(b1, a)
	else:
		res = min(a1, a)
	if abs(a - b) <= 3:
		res += 1
	return res

def solve():
	(n, x, m) = map(int, input().split())
	r = []
	for i in range(m):
		r.append(list(map(int, input().split())))
	end = x
	start = x
	count = 0
	if x >= start and x <= end:
		count = end - start + 1
	for i in range(0, m):
		if start <= r[i][1] and start >= r[i][0]:
			count += r[i][1] - r[i][0] + 1
			start = min(start, r[i][0])
			end = max(end, r[i][1])
		elif end <= r[i][1] and end >= r[i][0]:
			count += r[i][1] - r[i][0] + 1
			start = min(start, r[i][0])
			end = max(end, r[i][1])
	return end - start + 1
t = int(input())
for _ in range(t):
	r1 = solve()
	print(r1)


def solve(x, bounds):
	xl = x
	xr = x
	for b in bounds:
		if xl > b[0] and (not xl > b[1]):
			xl = b[0]
		if xr < b[1] and (not b[0] > xr):
			xr = b[1]
	return xr - xl + 1
input()
while True:
	try:
		val = input().split(' ')
		for i in range(len(val)):
			val[i] = int(val[i])
		arr = []
		for i in range(val[-1]):
			temp = input().split(' ')
			for i in range(len(temp)):
				temp[i] = int(temp[i])
			arr.append(temp)
		print(solve(val[1], arr))
	except EOFError:
		break


from sys import stdin
input = iter(stdin.readlines()).__next__
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	bounds = [tuple(map(int, input().split())) for _ in range(m)]
	(left, right) = (x, x)
	for (l, r) in bounds:
		if l < left and r >= left:
			left = l
		if r > right and l <= right:
			right = r
	print(right - left + 1)


import sys
input = sys.stdin.readline
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, x, m) = MI()
	(l, r) = (x, x)
	for __ in range(m):
		(a, b) = MI()
		if not (b < l or a > r):
			l = min(l, a)
			r = max(r, b)
	print(r - l + 1)


T = int(input())

def segments_union(segments):
	points = []
	result = 0
	for s in segments:
		points.append([s[0], True])
		points.append([s[1], False])
	points.sort(key=lambda x: x[0])
	counter = 0
	for (i, p) in enumerate(points):
		if counter > 0:
			result += p[0] - points[i - 1][0]
		if p[1]:
			counter += 1
		else:
			counter -= 1
	return result
for t_itr in range(T):
	(N, X, M) = map(int, input().rstrip().split())
	A = X
	B = X
	for _ in range(M):
		(L, R) = map(int, input().rstrip().split())
		if L <= A <= R:
			A = L
		if L <= B <= R:
			B = R
	print(B - A + 1)


list_ans = []
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	y = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if x <= b and y >= a:
			x = min(a, x)
			y = max(y, b)
	list_ans.append(y - x + 1)
print(*list_ans, sep='\n')


import math
import sys
import collections
from collections import defaultdict
from sys import stdin, stdout
for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	flag = 0
	minl = -1
	maxr = -1
	idx = -1
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if x >= l and x <= r:
			minl = l
			maxr = r
			idx = i
			flag = 1
			break
	if idx < m - 1 and idx != -1:
		for i in range(idx + 1, m):
			(l, r) = map(int, input().split())
			if l < minl and r < minl or (l > maxr and r > maxr):
				continue
			else:
				minl = min(l, minl)
				maxr = max(r, maxr)
	print(maxr - minl + 1)


t = int(input())
for i in range(t):
	inp = list(map(int, input().split()))
	n = inp[0]
	start = end = inp[1]
	m = inp[2]
	for x in range(m):
		inp = list(map(int, input().split()))
		s = inp[0]
		e = inp[1]
		if not (start < s and end < s or (start > e and end > e)):
			if s < start:
				start = s
			if e > end:
				end = e
	print(end - start + 1)


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


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, x, m) = sp()
	(start, end) = (x, x)
	for i in range(m):
		(a, b) = sp()
		if a <= start <= b or a <= end <= b:
			(start, end) = (min(start, a), max(b, end))
	out(end - start + 1)


import sys

def solve(n, x, ops):
	a = x
	b = x
	for (l, r) in ops:
		if r >= a and l <= b:
			(a, b) = (min(a, l), max(b, r))
	return b - a + 1
caseCount = int(next(sys.stdin))
ans = ''
for i in range(caseCount):
	(n, x, m) = [int(y) for y in next(sys.stdin)[:-1].split(' ')]
	ops = []
	for j in range(m):
		ops.append([int(y) for y in next(sys.stdin)[:-1].split(' ')])
	ans += str(solve(n, x, ops)) + '\n'
print(ans)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, x, m) = map(int, stdin.readline().split())
	(a, b) = (x, x)
	for _ in range(m):
		(l, r) = map(int, stdin.readline().split())
		if a >= l and a <= r:
			a = min(a, l)
		if b >= l and b <= r:
			b = max(b, r)
	stdout.write('{}\n'.format(b - a + 1))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mn = b
	mx = b
	for i in range(c):
		(x, y) = map(int, input().split())
		flg = 0
		if x <= mn and y >= mn or (x <= mx and y >= mx):
			mn = min(x, mn)
			mx = max(y, mx)
	print(mx - mn + 1)


t = int(input())
for dud in range(t):
	(n, x, m) = [int(x) for x in input().split()]
	l = x
	r = x
	turn = 0
	while turn < m:
		op = [int(x) for x in input().split()]
		if op[0] <= l <= op[1]:
			if op[0] < l:
				l = op[0]
		if op[0] <= r <= op[1]:
			if op[1] > r:
				r = op[1]
		turn += 1
	print(r - l + 1)


def solve():
	(n, x, m) = map(int, input().split())
	end = x
	start = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if r < start:
			continue
		if end < l:
			continue
		start = min(start, l)
		end = max(end, r)
	return end - start + 1
t = int(input())
for _ in range(t):
	print(solve())


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, x, m) = int_array()
	ans = (x, x)
	for __ in range(m):
		(l, r) = int_array()
		if l <= ans[1] and r >= ans[0]:
			l = min(l, ans[0])
			r = max(r, ans[1])
			ans = (l, r)
	print(ans[1] - ans[0] + 1)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, x, m) = value()
	ans = [x]
	ll = x
	rl = x
	for i in range(m):
		(l, r) = value()
		if r < ll or l > rl:
			continue
		else:
			ll = min(l, ll)
			rl = max(r, rl)
	print(rl - ll + 1)


from functools import reduce
I = lambda : map(int, input().split())

def f(rng, _):
	(l, r) = I()
	return rng if r < rng[0] or rng[1] < l else (min(rng[0], l), max(rng[1], r))
for _ in range(int(input())):
	(n, x, m) = I()
	print((lambda rng: rng[1] - rng[0] + 1)(reduce(f, range(m), (x, x))))


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	(al, ar) = (x, x)
	for j in range(m):
		(l, r) = map(int, input().split())
		nl = max(al, l)
		nr = min(ar, r)
		if nr >= nl:
			al = min(al, l)
			ar = max(ar, r)
	print(ar - al + 1)


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


t = int(input())
for t1 in range(t):
	(n, x, m) = [int(n1) for n1 in input().split()]
	point_left = x
	point_right = x
	for i in range(m):
		(l, r) = [int(n1) for n1 in input().split()]
		if l <= point_left <= r:
			point_left = l
		if l <= point_right <= r:
			point_right = r
	print(point_right - point_left + 1)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def intersect(left, right, a, b):
	if b < left or a > right:
		return 0
	return True
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	left = x
	right = x
	while m:
		(a, b) = map(int, input().split())
		if intersect(left, right, a, b):
			left = min(left, a)
			right = max(right, b)
		m -= 1
	print(right - left + 1)


def main():
	t = int(input())
	for _ in range(t):
		(n, x, m) = map(int, input().split())
		upper = lower = x
		for __ in range(m):
			(l, r) = map(int, input().split())
			if l < lower:
				if r >= lower:
					lower = l
			if r > upper:
				if l <= upper:
					upper = r
		print(upper - lower + 1)
main()


import math
t = int(input())
for i in range(t):
	inp = input().split(' ')
	(n, x, m) = (int(inp[0]), int(inp[1]), int(inp[2]))
	ops = []
	for j in range(m):
		inp = input().split(' ')
		(l, r) = (int(inp[0]), int(inp[1]))
		ops.append((l, r))
	min_index = x
	max_index = x
	for op in ops:
		if (min_index > op[1] or max_index < op[0]) == False:
			min_index = min(min_index, op[0])
			max_index = max(max_index, op[1])
	print(max_index - min_index + 1)


from sys import stdin, stdout
import math, collections

def solve():
	cases = int(input())
	for case in range(1, cases + 1):
		(n, x, m) = [int(n) for n in input().split()]
		lo = x
		up = x
		for i in range(m):
			(l, r) = [int(n) for n in input().split()]
			if l <= up and r >= lo:
				lo = min(l, lo)
				up = max(r, up)
		print(up - lo + 1)
solve()


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def myceil(x, y):
	return (x + y - 1) // y

def Solution():
	pass

def main():
	for _ in range(get_int()):
		(n, x, m) = get_ints_in_variables()
		(mn, mx) = (x, x)
		for _ in range(m):
			(l, r) = get_ints_in_variables()
			if l <= mn and r >= mn:
				mn = l
			if r >= mx and l <= mx:
				mx = r
		print(mx - mn + 1)
main()


def main():
	t = int(input())
	for _ in range(t):
		(n, x, m) = map(int, input().split())
		k_min = x
		k_max = x
		for i in range(m):
			(a, b) = map(int, input().split())
			if a <= k_min <= b or a <= k_max <= b:
				k_min = min(a, k_min)
				k_max = max(b, k_max)
		print(k_max - k_min + 1)
main()


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
tc = int(input())
for zz in range(tc):
	(n, x, m) = map(int, input().split())
	(l, h) = (x, x)
	for i in range(m):
		(a, b) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		if a <= l and b >= h:
			l = a
			h = b
		elif a < l and b >= l:
			l = a
		elif a <= h and b > h:
			h = b
	print(h - l + 1)


from math import *
from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
while t > 0:
	ip = [int(x) for x in input().split()]
	n = ip[0]
	x = ip[1]
	m = ip[2]
	flag = 0
	for i in range(m):
		(a, b) = [int(x) for x in input().split()]
		if flag == 0 and a <= x and (b >= x):
			flag = 1
			l = a
			r = b
		if flag == 1:
			if a < l and b >= l:
				l = a
			if b > r and a <= r:
				r = b
	if flag == 1:
		print(r - l + 1)
	else:
		print(1)
	t -= 1


for _ in range(int(input())):
	(n, x, m) = [int(c) for c in input().split()]
	r = x
	ans = 0
	arr = []
	for i in range(m):
		(a, b) = [int(c) for c in input().split()]
		arr.append((a, b))
	l = r
	for i in range(m):
		(a, b) = arr[i]
		if a <= l <= b or a <= r <= 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
T = ni()
for _ in range(T):
	solve()


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : map(int, cin().split())
for _ in range(int(cin())):
	(n, x, m) = mp()
	y = x
	for _ in range(m):
		(l, r) = mp()
		if y >= l <= r >= x:
			x = min(l, x)
			y = max(y, r)
	cout(str(y - x + 1) + '\n')


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	X_min = x
	X_max = x
	for _ in range(m):
		(l, r) = map(int, input().split())
		if X_min >= l and X_min <= r:
			X_min = l
		if X_max >= l and X_max <= r:
			X_max = r
	print(X_max - X_min + 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, x, m) = LI()
		a = [LI() for _ in range(m)]
		l = r = x
		for (c, d) in a:
			if c < l <= d:
				l = c
			if c <= r < d:
				r = d
		rr.append(r - l + 1)
	return JA(rr, '\n')
print(main())


t = int(input())
while t != 0:
	t -= 1
	(n, x, m) = map(int, input().split())
	(low, high) = (x, x)
	for _ in range(m):
		(l, r) = map(int, input().split())
		if low <= l and r <= high or high < l or r < low:
			continue
		else:
			low = min(low, l)
			high = max(high, r)
	print(high - low + 1)


def f():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(n, k, m) = f()
	p = q = k
	for _ in range(m):
		(a, b) = f()
		if a <= p <= b or a <= q <= b:
			p = min(p, a)
			q = max(q, b)
	print(q - p + 1)


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


import sys
input = sys.stdin.readline
x = int(input())
for i in range(x):
	(a, b, c) = list(map(int, input().split()))
	(l, r) = (b, b)
	for j in range(c):
		(x, y) = list(map(int, input().split()))
		if l >= x and l <= y:
			l = x
		if r >= x and r <= y:
			r = y
	print(abs(l - r) + 1)


def shuf(n, x, m):
	start = -1
	end = -1
	for i in range(len(m)):
		if x >= m[i][0] and x <= m[i][1]:
			start = m[i][0]
			end = m[i][1]
			for j in range(i + 1, len(m)):
				if m[j][0] <= start and m[j][1] >= start or (m[j][0] <= end and m[j][1] >= end):
					start = min(m[j][0], start)
					end = max(m[j][1], end)
			break
	return end - start + 1
t = int(input())
l = []
for i in range(t):
	(n, x, m) = list(map(int, input().split()))
	ml = []
	for i in range(m):
		q = list(map(int, input().split()))
		ml.append(q)
	l.append([n, x, ml])
for r in l:
	print(shuf(*r))


for _ in range(int(input())):
	(n, x, m) = list(map(int, input().split()))
	u = 0
	k = 0
	for _ in range(m):
		(s, e) = list(map(int, input().split()))
		k += 1
		if x in range(s, e + 1):
			cs = s
			ce = e
			u = 1
			break
	if u == 0:
		print(1)
		continue
	for _ in range(m - k):
		(s, e) = list(map(int, input().split()))
		if s >= cs and s <= ce:
			ce = max(ce, e)
		elif s <= cs and e >= cs:
			cs = s
			ce = max(e, ce)
	print(ce - cs + 1)


for ttt in range(int(input())):
	(n, x, m) = map(int, input().split())
	p1 = x
	p2 = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= p2 and r >= p2:
			p2 = r
		if l <= p1 and r >= p1:
			p1 = l
	print(p2 - p1 + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(m)]
	(p, q) = (x, x)
	for z in a:
		(i, j) = (z[0], z[1])
		if p >= i and p <= j:
			p = min(p, i)
		if q >= i and q <= j:
			q = max(q, j)
	print(q - p + 1)


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


import sys
input = sys.stdin.readline
import math as ma
t = int(input())
for _ in range(t):
	(n, x, m) = list(map(int, input().split()))
	mi = x
	ma = x
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if l <= ma <= r:
			ma = r
		if l <= mi <= r:
			mi = l
	print(ma - mi + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	rang = [x, x]
	for i in range(m):
		(L, R) = map(int, input().split())
		if L < rang[0] <= R:
			rang[0] = L
		if R > rang[1] >= L:
			rang[1] = R
	print(rang[1] - rang[0] + 1)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	(n, x, m) = map(int, stdin.readline().split())
	ans = (x, x)
	for _ in range(m):
		(l, r) = map(int, stdin.readline().split())
		if ans[0] <= r and ans[1] >= l:
			ans = (min(l, ans[0]), max(r, ans[1]))
	print(ans[1] - ans[0] + 1)


import sys
import math
from sys import stdin, stdout

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def main():
	for t in range(int(input())):
		(n, x, m) = get_ints()
		c = 0
		l1 = 0
		r1 = 0
		d = 0
		for i in range(m):
			(l, r) = get_ints()
			if x >= l and x <= r and (d == 0):
				d = 1
				l1 = l
				r1 = r
			if d == 1:
				if l >= l1 and l <= r1 and (r >= r1):
					r1 = r
				elif l < l1 and r >= l1 and (r <= r1):
					l1 = l
				elif l < l1 and r > r1:
					l1 = l
					r1 = r
		if d == 1:
			print(r1 - l1 + 1)
		else:
			print(1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = int(stdin.readline())
for _ in range(t):
	(n, x, m) = list(map(int, stdin.readline().rstrip().split()))
	d = {}
	(mi, mx) = (x, x)
	for i in range(m):
		(l, r) = list(map(int, stdin.readline().rstrip().split()))
		if x <= r and x >= l:
			if mi > l:
				mi = l
			if mx < r:
				mx = r
		elif r >= mi and r <= mx or (l >= mi and l <= mx):
			if mi > l:
				mi = l
			if mx < r:
				mx = r
	ans = mx - mi + 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, posof1, m) = list(map(int, input().split(' ')))
	res = 0
	begin = posof1
	end = posof1
	for x in range(m):
		temp = list(map(int, input().split(' ')))
		if temp[0] <= begin <= temp[1] or temp[0] <= end <= temp[1]:
			begin = min(begin, temp[0])
			end = max(end, temp[1])
	print(end - begin + 1)


ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
for _ in range(ii()):
	(n, x, m) = f()
	c = 0
	mi = 0
	mx = 0
	for i in range(0, m):
		(a, b) = f()
		if a <= x <= b and c == 0:
			mi = a
			mx = b
			c = c + 1
		elif a <= x <= b and c >= 1:
			mi = min(mi, a)
			mx = max(mx, b)
		elif mi <= a <= mx or mi <= b <= mx:
			mi = min(mi, a)
			mx = max(mx, b)
	print(mx - mi + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	l = []
	r = []
	for _ in range(m):
		(li, ri) = map(int, input().split())
		l.append(li)
		r.append(ri)
	i = 0
	pos_min_val = x
	pos_max_val = x
	while i < m and pos_max_val - pos_min_val < n - 1:
		if r[i] >= pos_min_val and l[i] <= pos_max_val:
			pos_min_val = min(pos_min_val, l[i])
			pos_max_val = max(pos_max_val, r[i])
		i += 1
	print(pos_max_val - pos_min_val + 1)


cases = int(input())
for i in range(cases):
	l1 = input().split(' ')
	n = int(l1[0])
	xmi = xma = int(l1[1])
	m = int(l1[2])
	index = []
	pos = 0
	for j in range(m):
		op = input().split(' ')
		left = int(op[0])
		right = int(op[1])
		if xmi >= left and xma <= right:
			xmi = left
			xma = right
		elif right == xmi:
			xmi = left
		elif xma == left:
			xma = right
		elif left >= xmi and left <= xma and (right > xma):
			xma = right
		elif right < xma and right >= xmi and (left < xmi):
			xmi = left
	print(xma - xmi + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	x1 = 10 ** 10
	x2 = -1
	for j in range(m):
		(a, b) = map(int, input().split())
		if a <= x <= b or a <= x1 <= b or a <= x2 <= b or (x1 <= a and b <= x2):
			x1 = min(a, x1)
			x2 = max(b, x2)
	print(x2 - x1 + 1) if x2 >= 1 and x1 >= 1 else print(1)


tests = int(input())
for i in range(tests):
	numbers = input().split(' ')
	n = int(numbers[0])
	x = int(numbers[1])
	m = int(numbers[2])
	left = x
	right = x
	for j in range(m):
		numbers = input().split(' ')
		d1 = int(numbers[0])
		d2 = int(numbers[1])
		if d1 <= left <= d2:
			left = d1
		if d1 <= right <= d2:
			right = d2
	print(right - left + 1)


from collections import defaultdict
for t in range(int(input())):
	(n, x, m) = [int(i) for i in input().split()]
	d = [[int(i) for i in input().split()] for j in range(m)]
	i = x
	j = x
	for (s, e) in d:
		if s >= i and s <= j or (e >= i and e <= j) or (s <= i and e >= j):
			i = min(s, i)
			j = max(e, j)
	print(j - i + 1)


from sys import stdin, stdout
import math
input = stdin.readline

def print(x):
	stdout.write(str(x) + '\n')

def solve():
	(n, x, m) = map(int, input().split())
	(s, e) = (x, x)
	for i in range(m):
		(u, v) = map(int, input().split())
		if s <= u <= e or s <= v <= e or (s >= u and e <= v):
			s = min(s, u)
			e = max(e, v)
	print(e - s + 1)
t = 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, x, m) = (int(var) for var in input().split())
	(L, R) = (x, x)
	for _ in range(m):
		(l, r) = (int(var) for var in input().split())
		if R >= l and L <= r or (r >= L and l <= R):
			L = min(L, l)
			R = max(R, r)
	print(R - L + 1)


T = int(input())
for t in range(T):
	U = list(map(int, input().split()))
	(n, x, m) = (U[0], U[1], U[2])
	p = []
	for i in range(m):
		L = list(map(int, input().split()))
		p.append(L)
	lo = -1
	hi = -1
	for u in range(m):
		if p[u][0] <= x <= p[u][1]:
			count = u
			lo = p[u][0]
			hi = p[u][1]
			break
		else:
			continue
	if lo != -1 and hi != -1:
		for s in range(count + 1, m):
			x = max(lo, p[s][0])
			y = min(hi, p[s][1])
			if x <= y:
				lo = min(lo, p[s][0])
				hi = max(hi, p[s][1])
	print(hi - lo + 1)


import sys
input = sys.stdin.readline

def solve(n, x, m, edges):
	(low, high) = (None, None)
	for (l, r) in edges:
		if l <= x <= r:
			if low == None and high == None:
				low = l
				high = r
			else:
				low = min(low, l)
				high = max(high, r)
		elif (low != None and high != None) and (l <= low <= r or l <= high <= r):
			low = min(low, l)
			high = max(high, r)
	if low == high == None:
		return 1
	else:
		return high - low + 1
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	edges = []
	for _ in range(m):
		(l, r) = map(int, input().split())
		edges.append((l, r))
	print(solve(n, x, m, edges))


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict, Counter
for _ in range(ri()):
	(n, x, m) = ria()
	a = b = x
	for __ in range(m):
		(l, r) = ria()
		if a >= l and a <= r:
			a = l
		if b >= l and b <= r:
			b = r
	wi(b - a + 1)


def main():
	(n, x, m) = map(int, input().split())
	(l, r) = (x, x)
	for _ in range(m):
		(a, b) = map(int, input().split())
		if b < l or a > r:
			continue
		else:
			l = min(l, a)
			r = max(r, b)
	print(r - l + 1)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


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 inbw(l, r):
	if l <= l1 and r >= l1:
		return True
	if l <= r1 and r >= r1:
		return True
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	l1 = x
	r1 = x
	count = 1
	for w in range(m):
		(l, r) = map(int, input().split())
		if inbw(l, r):
			if l <= l1:
				count += l1 - l
			if r >= r1:
				count += r - r1
			l1 = min(l, l1)
			r1 = max(r, r1)
	print(count)


t = int(input(''))
while t > 0:
	(n, x, m) = map(int, input().split())
	operations = []
	for i in range(m):
		l = tuple(map(int, input().split()))
		operations.append(l)
	possible = []
	a = []
	go_time = 0
	for (l, h) in operations:
		if go_time == 0:
			if x >= l and x <= h:
				go_time = 1
				lowest = l
				highest = h
		else:
			if l < lowest and h >= lowest:
				lowest = l
			if h > highest and l <= highest:
				highest = h
	if go_time == 1:
		print(highest - lowest + 1)
	else:
		print(1)
	t -= 1


for i in range(int(input())):
	(n, k, m) = map(int, input().split())
	(a, b) = (k, k)
	for j in range(m):
		(p, q) = map(int, input().split())
		if q >= a and b >= p:
			a = min(p, a)
			b = max(q, b)
	print(b - a + 1)


t = int(input())
for case in range(t):
	[n, x, m] = list(map(int, input().split()))
	(l, r) = (0, 0)
	flag = False
	for j in range(m):
		[nl, nr] = list(map(int, input().split()))
		if not flag:
			if nl <= x <= nr:
				(l, r) = (nl, nr)
				flag = True
		elif nr >= l and nl <= r:
			(l, r) = (min(l, nl), max(r, nr))
	if not flag:
		print(1)
	else:
		print(r - l + 1)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	(n, x, m) = input().split()
	n = int(n)
	m = int(m)
	x = int(x)
	allx = [x, x]
	for _ in range(m):
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		if allx[1] >= l and allx[0] <= r:
			allx[0] = min([l, allx[0]])
			allx[1] = max([r, allx[1]])
	print(allx[1] - allx[0] + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	f = s = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= f <= b:
			f = a
		if a <= s <= b:
			s = b
	print(s - f + 1)


MOD = 1000007
ii = lambda : int(input())
f = lambda : map(int, input().split())
for _ in range(ii()):
	C = 0
	(n, x, m) = f()
	c = 0
	mi = 0
	mx = 0
	L = 0
	for i in range(0, m):
		(a, b) = f()
		if a <= x <= b and c == 0:
			mi = a
			mx = b
			c = c + 1
			P = 0
		elif a <= x <= b and c >= 1:
			mi = min(mi, a)
			mx = max(mx, b)
			K = 0
		elif mi <= a <= mx or mi <= b <= mx:
			mi = min(mi, a)
			mx = max(mx, b)
	print(mx - mi + 1)


try:
	for _ in range(int(input())):
		(n, x, m) = map(int, input().split())
		l = r = x
		for __ in range(m):
			(a, b) = map(int, input().split())
			if a > r or b < l:
				continue
			l = min(a, l)
			r = max(b, r)
		print(r - l + 1)
except EOFError:
	pass


import math
a = int(input())
for i in range(a):
	(n, x, m) = map(int, input().split())
	mini = math.inf
	maxa = 0
	for i in range(m):
		(p, q) = map(int, input().split())
		if p <= x <= q:
			mini = min(mini, p)
			maxa = max(maxa, q)
		else:
			if p <= mini <= q:
				mini = p
			if p <= maxa <= q:
				maxa = q
	if mini == math.inf:
		print(1)
	else:
		print(maxa - mini + 1)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	c = 0
	l = 0
	r = 0
	for i in range(m):
		(n1, n2) = map(int, input().split())
		if c == 0:
			if x >= n1 and x <= n2:
				c = 1
				l = n1
				r = n2
		else:
			if n1 <= l and n2 >= l:
				l = n1
			if n1 <= r and n2 >= r:
				r = n2
	print(r - l + 1)


def solve():
	(n, x, m) = map(int, input().split())
	(al, ar) = (x, x)
	for _ in range(m):
		(li, ri) = map(int, input().split())
		if li <= al and al <= ri:
			al = li
		if li <= ar and ar <= ri:
			ar = ri
	print(ar - al + 1)
t = int(input())
while t > 0:
	t -= 1
	solve()


import sys
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	l = []
	a = []
	for i in range(m):
		l = list(map(int, input().split()))
		a.append(l)
	ans = []
	st = x
	en = x
	for i in range(len(a)):
		if st >= a[i][0] and en <= a[i][1]:
			st = a[i][0]
			en = a[i][1]
		elif en <= a[i][1] and en >= a[i][0]:
			en = a[i][1]
		elif st <= a[i][1] and st >= a[i][0]:
			st = a[i][0]
	print(en - st + 1)


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


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


import math
t = int(input())
for i in range(t):
	(n, x, m) = list(map(int, input().split()))
	min_range = x
	max_range = x
	for j in range(m):
		(l, r) = list(map(int, input().split()))
		if x >= l and x <= r:
			if l < min_range:
				min_range = l
			if r > max_range:
				max_range = r
		elif min_range >= l and min_range <= r or (max_range >= l and max_range <= r):
			if l < min_range:
				min_range = l
			if r > max_range:
				max_range = r
	count = max_range - min_range + 1
	print(count)


cases = int(input())
for t in range(cases):
	(n, x, m) = list(map(int, input().split()))
	lmax = x
	rmax = x
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		if l <= lmax and r >= lmax or (r >= rmax and l <= rmax):
			lmax = min(l, lmax)
			rmax = max(r, rmax)
	print(rmax - lmax + 1)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	a = []
	for i in range(m):
		(l, r) = map(int, input().split())
		a.append([l, r])
	val = [x, x]
	for i in range(m):
		cur = [max(val[0], a[i][0]), min(val[1], a[i][1])]
		if cur[0] <= cur[1]:
			val = [min(a[i][0], val[0]), max(a[i][1], val[1])]
	print(val[1] - val[0] + 1)


tests = int(input())
for _ in range(tests):
	(n, x, m) = map(int, input().split())
	a1 = x
	b1 = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a1 >= a and a1 <= b or (b1 <= b and b1 >= a):
			if a < a1:
				a1 = a
			if b1 < b:
				b1 = b
	print(b1 - a1 + 1)


t = int(input())
for we in range(t):
	(n, x, m) = map(int, input().split())
	k = 0
	(cl, cr) = map(int, input().split())
	d = 0
	if x >= cl and x <= cr:
		d = 1
	for wee in range(m - 1):
		(l, r) = map(int, input().split())
		if d == 0:
			if x >= l and x <= r:
				cl = l
				cr = r
				d = 1
		if d == 1:
			if cl > l and r >= cl:
				cl = l
			if cr < r and l <= cr:
				cr = r
	if d == 1:
		k = abs(cl - cr) + 1
	else:
		k = 1
	print(k)


def f():
	(n, x, m) = [int(s) for s in input().split()]

	def merge(x, y, a, b):
		if y < a or x > b:
			return (x, y)
		return (min(x, a), max(y, b))
	(x, y) = (x, x)
	for _ in range(m):
		(a, b) = [int(s) for s in input().split()]
		(x, y) = merge(x, y, a, b)
	print(y - x + 1)
for t in range(int(input())):
	f()


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


t = int(input())
for _ in range(t):
	a = [int(x) for x in input().split()]
	(n, x, m) = (a[0], a[1], a[2])
	mn = x
	mx = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if mx >= l and r >= mn:
			mn = min(mn, l)
			mx = max(mx, r)
	print(mx - mn + 1)


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


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def overlapping(a, b):
	return min(a[1], b[1]) - max(a[0], b[0]) >= 0

def overlap(a, b):
	return (min(a[0], b[0]), max(a[1], b[1]))

def solve(n, x, m, ops):
	i = 0
	while i < m and (x < ops[i][0] or x > ops[i][1]):
		i += 1
	if i >= m:
		return 1
	s = ops[i]
	for j in range(i + 1, m):
		if overlapping(s, ops[j]):
			s = overlap(s, ops[j])
	return s[1] - s[0] + 1

def main():
	for _ in range(ri()):
		(n, x, m) = ria()
		ops = []
		for _ in range(m):
			ops.append(tuple(ria()))
		wi(solve(n, x, m, ops))
main()


t = int(input())
for i in range(t):
	(n, x, m) = map(int, input().split())
	(a, b) = (0, 0)
	while m:
		(a, b) = map(int, input().split())
		m -= 1
		if a <= x <= b:
			break
		(a, b) = (0, 0)
	while m:
		(c, d) = map(int, input().split())
		m -= 1
		if a <= c <= b or c <= a <= d:
			(a, b) = (min(a, c), max(b, d))
	print(b - a + 1)


t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	(left, right) = (x - 1, x - 1)
	count = 0
	for _ in range(m):
		(l, r) = map(int, input().split())
		l = l - 1
		r = r - 1
		if l <= left <= r or l <= right <= r:
			left = min(l, left)
			right = max(r, right)
	print(right - left + 1)


import math
t = int(input())
for i in range(0, t):
	nxm = input().split()
	n = int(nxm[0])
	x = int(nxm[1])
	m = int(nxm[2])
	xmin = x
	xmax = x
	for i in range(0, m):
		lr = input().split()
		l = int(lr[0])
		r = int(lr[1])
		if l <= xmin <= r:
			xmin = l
		if l <= xmax <= r:
			xmax = r
	print(xmax - xmin + 1)


def solve():
	(n, x, m) = [int(v) for v in input().split()]
	arr = []
	currpl = x
	currpr = x
	for i in range(m):
		(l, r) = [int(v) for v in input().split()]
		if currpl >= l and currpl <= r or (currpr >= l and currpr <= r):
			currpl = min(currpl, l)
			currpr = max(currpr, r)
	print(currpr - currpl + 1)
t = int(input())
for _ in range(t):
	solve()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)

class UnionFind:

	def __init__(self, n):
		self.table = [-1] * n

	def _root(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self._root(self.table[x])
			return self.table[x]

	def find(self, x, y):
		return self._root(x) == self._root(y)

	def union(self, x, y):
		r1 = self._root(x)
		r2 = self._root(y)
		if r1 == r2:
			return
		d1 = self.table[r1]
		d2 = self.table[r2]
		if d1 <= d2:
			self.table[r2] = r1
			if d1 == d2:
				self.table[r1] -= 1
		else:
			self.table[r1] = r2

	def __str__(self):
		rt = [i if j < 0 else j for (i, j) in enumerate(self.table)]
		return str(rt)
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	ans = 0
	(n, x, m) = LI()
	(inf, sup) = (x, x)
	for i in range(m):
		(l, r) = LI()
		if l <= inf <= r or l <= sup <= r:
			inf = min(l, inf)
			sup = max(r, sup)
	ans = sup - inf + 1
	print(ans)


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	the_borders = [0, 0]
	flag = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r and flag == 0:
			flag = 1
			(the_borders[0], the_borders[1]) = (l, r)
			continue
		elif flag == 1:
			if the_borders[0] <= l <= the_borders[1] or the_borders[0] <= r <= the_borders[1] or l <= the_borders[0] <= r or (l <= the_borders[1] <= r):
				the_borders[0] = l if the_borders[0] > l else the_borders[0]
				the_borders[1] = r if the_borders[1] < r else the_borders[1]
	print(the_borders[1] - the_borders[0] + 1)


def solve():
	(n, x, m) = map(int, input().split())
	lr = [tuple(map(int, input().split())) for i in range(m)]
	(l, r) = (x, x)
	for i in range(m):
		if r < lr[i][0] or l > lr[i][1]:
			continue
		l = min(lr[i][0], l)
		r = max(lr[i][1], r)
	print(r - l + 1)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
ans = []
for _ in range(t):
	(n, x, m) = map(int, input().split())
	(right, left) = (x, x)
	for i in range(m):
		(l, r) = map(int, input().split())
		if left <= r and l <= right:
			left = min(l, left)
			right = max(r, right)
	ans.append(right - left + 1)
print('\n'.join(map(str, ans)))


t = int(input())
for y in range(t):
	aq = input().split()
	n = int(aq[0])
	x = int(aq[1])
	m = int(aq[2])
	a = x
	b = x
	count = 1
	for i in range(m):
		z = input().split()
		l = int(z[0])
		r = int(z[1])
		if l <= a and (r <= b and r >= a):
			count += a - l
			a = l
		elif (l >= a and l <= b) and r >= b:
			count += r - b
			b = r
		elif l <= a and r >= b:
			count += a + r - (l + b)
			a = l
			b = r
	print(count)


import math
t = int(input())
while t > 0:
	t -= 1
	(n, x, m) = map(int, input().split())
	y = x
	z = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if y >= a and y <= b or (z >= a and z <= b) or (y <= a and z >= b):
			y = min(y, a)
			z = max(z, b)
	print(z - y + 1)


from collections import defaultdict
INF = float('inf')
t = int(input())
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))

def solve(n, x, m, ops):
	best = 1
	(lo, hi) = (x, x)
	for (s, f) in ops:
		if s <= x <= f or lo <= s <= hi or lo <= f <= hi:
			lo = min(lo, s)
			hi = max(hi, f)
			best = max(hi - lo + 1, best)
	return best
for _ in range(t):
	(n, x, m) = rrm()
	ops = []
	for _ in range(m):
		ops.append(rrm())
	print(solve(n, x, m, ops))


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(n, x, m) = num_input()
	L = R = x
	for _ in range(m):
		(l, r) = num_input()
		if l <= L and r >= R:
			(L, R) = (l, r)
		elif r > R:
			if l >= L and l <= R:
				R = r
		elif l < L:
			if r >= L and r <= R:
				L = l
	print(R - L + 1)
t = int(input())
for _ in range(t):
	solve()


T = int(input())
for _ in range(T):
	(n, x, m) = map(int, input().strip().split())
	possible_bounds = [(x, x)]
	for _ in range(m):
		(l, r) = map(int, input().strip().split())
		for bound in possible_bounds:
			(lower, upper) = bound
			if not (l > upper or r < lower):
				possible_bounds.append((l, r))
				break
	res = 0
	(curr_l, curr_r) = (n + 1, -1)
	for bound in possible_bounds:
		(l, r) = bound
		curr_l = min(curr_l, l)
		curr_r = max(curr_r, r)
	res += curr_r - curr_l + 1
	print(res)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['Yes', 'No']
test_case = ii()
while test_case:
	test_case -= 1
	(n, x, m) = mi()
	y = x
	for _ in range(m):
		(l, r) = mi()
		if l <= x <= r:
			x = l
		if l <= y <= r:
			y = r
	print(y - x + 1)


t = int(input())
while t:
	(n, x, m) = map(int, input().split())
	y = x
	while m:
		(l, r) = map(int, input().split())
		if l <= x and x <= r:
			x = l
		if l <= y and y <= r:
			y = r
		m = m - 1
	print(str(y - x + 1))
	t = t - 1


t = int(input())
results = []
for case in range(t):
	(n, x, m) = map(int, input().split())
	start = x
	end = x
	for operation in range(m):
		(l, r) = map(int, input().split())
		if l <= start <= r or l <= end <= r:
			start = min(start, l)
			end = max(end, r)
	k = end - start + 1
	results.append(k)
for result in results:
	print(result)


test = int(input())
for t in range(test):
	(n, x, m) = map(int, input().split())
	prvL = x - 1
	prvR = x - 1
	for x in range(m):
		(l, r) = map(int, input().split())
		l = l - 1
		r = r - 1
		if r < prvL:
			continue
		elif l > prvR:
			continue
		prvL = min(prvL, l)
		prvR = max(prvR, r)
	count = prvR - prvL + 1
	print(count)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def instr():
	return str(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from collections import Counter

def main():
	t = inp()
	for _ in range(t):
		(n, x, m) = inlt()
		(left, right) = (x, x)
		for _ in range(m):
			(l, r) = inlt()
			if r >= left:
				left = min(l, left)
			if l <= right:
				right = max(r, right)
		print(right - left + 1)
main()


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, x, m) = map(int, stdin.readline().strip().split())
	flg = 0
	for i in range(m):
		(l, r) = map(int, stdin.readline().strip().split())
		if flg == 0 and x >= l and (x <= r):
			flg = 1
			c = l
			d = r
		elif flg == 1:
			if r >= c and l <= d:
				c = min(c, l)
				d = max(d, r)
	if flg == 0:
		print(1)
	else:
		print(d - c + 1)


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
	os.write(1, '\n'.encode())
T = read_i()
while T:
	T -= 1
	(n, x, m) = [read_i() for i in range(3)]
	left = x
	right = x
	for i in range(m):
		l = read_i()
		r = read_i()
		if left <= r and l <= right:
			left = min(left, l)
			right = max(right, r)
	write_i(right - left + 1)
print_ans()


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	ok = False
	maxr = 0
	maxl = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r and (not ok):
			maxl = l
			maxr = r
			ok = True
		elif ok:
			if not (maxr < l or r < maxl):
				maxl = min(maxl, l)
				maxr = max(maxr, r)
	if not ok:
		print(1)
	else:
		print(maxr - maxl + 1)


import os
import sys
from io import BytesIO, IOBase

def readvars():
	k = map(int, input().split())
	return k

def readlist():
	li = list(map(int, input().split()))
	return li

def anslist(li):
	ans = ' '.join([str(v) for v in li])
	return ans

def main():
	t = 1
	t = int(input())
	for xx in range(t):
		(n, x, m) = readvars()
		(rangel, ranger) = (x, x)
		for i in range(m):
			(l, r) = readvars()
			if l <= ranger and r > ranger:
				rangel = min(rangel, l)
				ranger = r
			if r >= rangel and l < rangel:
				ranger = max(ranger, r)
				rangel = l
		print(ranger - rangel + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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


for n in range(int(input())):
	(k, x, m) = [int(i) for i in input().split()]
	(ml, mr) = (x, x)
	for i in range(m):
		(l, r) = [int(b) for b in input().split()]
		if r >= ml >= l:
			ml = l
		if l <= mr < r:
			mr = r
	print(mr - ml + 1)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	nxm = stdin.readline().split()
	n = int(nxm[0])
	x = int(nxm[1])
	m = int(nxm[2])
	bound1 = x
	bound2 = x
	for l in range(m):
		interval = stdin.readline().split()
		start = int(interval[0])
		end = int(interval[1])
		bool1 = bound1 >= start and bound1 <= end
		bool3 = bound2 >= start and bound2 <= end
		bool2 = start <= bound1 and end >= bound2
		if bool1 or bool2 or bool3:
			bound1 = min(bound1, start)
			bound2 = max(bound2, end)
	stdout.write(str(bound2 - bound1 + 1) + '\n')


for _ in range(int(input())):
	(n, x, m) = map(int, input().split())
	t1 = 10000000000
	t2 = -1
	ans = 0
	amn = x
	amx = x
	for i in range(m):
		(a, b) = map(int, input().split())
		if a <= amn <= b or a <= amx <= b:
			amn = min(amn, a)
			amx = max(amx, b)
	print(amx - amn + 1)


for t in range(int(input())):
	(n, x, m) = map(int, input().split())
	start = stop = x
	for i in range(m):
		(l, r) = map(int, input().split())
		if start <= r and start > l:
			start = l
			if stop < r:
				stop = r
		elif stop >= l and (not r < start):
			if stop < r:
				stop = r
			if start > l:
				start = l
	print(stop - start + 1)


t = int(input())
for i in range(t):
	(n, x, m) = [int(a) for a in input().split()]
	left = x
	right = x
	for j in range(m):
		(l, r) = [int(a) for a in input().split()]
		if left == l or right == r or left == r or (right == l) or (l < right < r) or (l < left < r):
			if left > l:
				left = l
			if right < r:
				right = r
	print(right - left + 1)


def solve():
	F = int(input())
	for J in range(F):
		(K, D, G) = list(map(int, input().split()))
		E = []
		for L in range(G):
			(H, I) = list(map(int, input().split()))
			E.append((H, I))
		A = D
		B = D
		for C in E:
			if C[1] < A or C[0] > B:
				continue
			A = min(A, C[0])
			B = max(B, C[1])
		print(B - A + 1)
solve()


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


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
t = int(input())
for _ in range(t):
	(n, x, m) = map(int, input().split())
	flag = 0
	rsf = [-1, -1]
	for tup in range(m):
		(l, r) = map(int, input().split())
		if l <= x <= r or flag:
			flag = 1
			if rsf == [-1, -1]:
				rsf = [l, r]
			elif l <= rsf[0] <= r or l <= rsf[1] <= r:
				rsf = [min(rsf[0], l), max(rsf[1], r)]
	print(rsf[1] - rsf[0] + 1 if rsf != [-1, -1] else 1)


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


import sys
import random
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(n, x, m) = intInp()
	ran = [x, x]
	for i in range(m):
		(a, b) = intInp()
		if ran[0] >= a and ran[0] <= b or (ran[1] >= a and ran[1] <= b):
			ran = [min(a, b, ran[0], ran[1]), max(a, b, ran[0], ran[1])]
	print(ran[1] - ran[0] + 1)


def solve():
	temp = input()
	temp.strip()
	(n, x, m) = temp.split()
	n = int(n)
	x = int(x)
	m = int(m)
	maxi = 0
	mini = 10000000000.0
	f = 0
	while m:
		m -= 1
		temp = input()
		temp.strip()
		(l, r) = temp.split()
		l = int(l)
		r = int(r)
		if f == 0:
			if l <= x and r >= x:
				f = 1
				maxi = r
				mini = l
		else:
			if l > maxi:
				continue
			if r < mini:
				continue
			mini = min(mini, l)
			maxi = max(maxi, r)
	if mini == 10000000000.0:
		print(1)
	else:
		print(maxi - mini + 1)

def main():
	tt = int(input())
	while tt > 0:
		solve()
		tt -= 1
main()


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


def intersect(a1, b1, a2, b2):
	if b2 >= a1 and b2 <= b1:
		return True
	elif a2 >= a1 and a2 <= b1:
		return True
	elif a2 <= a1 and b2 >= b1:
		return True
	else:
		return False
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 intersect(a, b, l, r):
			a = min(a, l)
			b = max(b, r)
	print(b - a + 1)


for i in range(int(input())):
	(n, x, m) = [int(k) for k in input().split()]
	anshigh = None
	for i in range(m):
		(l, r) = [int(k) for k in input().split()]
		if not anshigh:
			if l <= x and x <= r:
				anslow = l
				anshigh = r
		else:
			if l < anslow and r >= anslow:
				anslow = l
			if anshigh < r and l <= anshigh:
				anshigh = r
	if not anshigh:
		print('1')
	else:
		print(anshigh - anslow + 1)


cases = int(input())
prevIndex = -2
prevM = 0
for i in range(cases):
	(n, x, m) = map(int, input().split())
	potentialk = [x, x]
	for j in range(m):
		(l, r) = map(int, input().split())
		if potentialk[0] <= l and l <= potentialk[1] <= r:
			potentialk[1] = r
		elif l <= potentialk[0] <= r and r <= potentialk[1]:
			potentialk[0] = l
		elif l <= potentialk[0] and potentialk[1] <= r:
			potentialk[0] = l
			potentialk[1] = r
	print(potentialk[1] - potentialk[0] + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(n, x, m) = RL()
		tag = False
		(lb, rb) = (0, 0)
		for _ in range(m):
			(l, r) = RL()
			if tag:
				if lb <= l <= rb or lb <= r <= rb or (r >= rb and l <= lb):
					lb = min(lb, l)
					rb = max(rb, r)
			elif l <= x <= r:
				tag = True
				(lb, rb) = (l, r)
		print(rb - lb + 1)
main()


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