Your math teacher gave you the following problem:

There are $n$ segments on the $x$-axis, $[l_1; r_1], [l_2; r_2], \ldots, [l_n; r_n]$. The segment $[l; r]$ includes the bounds, i.e. it is a set of such $x$ that $l \le x \le r$. The length of the segment $[l; r]$ is equal to $r - l$.

Two segments $[a; b]$ and $[c; d]$ have a common point (intersect) if there exists $x$ that $a \leq x \leq b$ and $c \leq x \leq d$. For example, $[2; 5]$ and $[3; 10]$ have a common point, but $[5; 6]$ and $[1; 4]$ don't have.

You should add one segment, which has at least one common point with each of the given segments and as short as possible (i.e. has minimal length). The required segment can degenerate to be a point (i.e a segment with length zero). The added segment may or may not be among the given $n$ segments.

In other words, you need to find a segment $[a; b]$, such that $[a; b]$ and every $[l_i; r_i]$ have a common point for each $i$, and $b-a$ is minimal.


-----Input-----

The first line contains integer number $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 10^{5}$) — the number of segments. The following $n$ lines contain segment descriptions: the $i$-th of them contains two integers $l_i,r_i$ ($1 \le l_i \le r_i \le 10^{9}$).

The sum of all values $n$ over all the test cases in the input doesn't exceed $10^5$.


-----Output-----

For each test case, output one integer — the smallest possible length of the segment which has at least one common point with all given segments.


-----Example-----
Input
4
3
4 5
5 9
7 7
5
11 19
4 17
16 16
3 12
14 17
1
1 10
1
1 1

Output
2
4
0
0



-----Note-----

In the first test case of the example, we can choose the segment $[5;7]$ as the answer. It is the shortest segment that has at least one common point with all given segments.

Difficulty: interview

Starter code:

Solutions:
for __ in range(int(input())):
    n = int(input())
    ar = []
    for ________ in range(n):
        ar.append(list(map(int, input().split())))
    ar.sort(key=lambda x: x[1])
    num1 = ar[0][1]
    ar.sort(key=lambda x: -x[0])
    num2 = ar[0][0]
    print(max(0, num2 - num1))

t = int(input())
for faw in range(t):
    n = int(input())
    mal = -1
    mir = 10000000000000
    for i in range(n):
        l,r = list(map(int,input().split()))
        mal = max(mal, l)
        mir = min(mir, r)
    print(max(mal - mir, 0))


t = int(input())
for i in range(t):
    n = int(input())
    min_r = 10 ** 10
    max_l = -(10 ** 10)
    for j in range(n):
        a, b = list(map(int, input().split()))
        if a > max_l:
            max_l = a
        if b < min_r:
            min_r = b
    print(max(0, -min_r + max_l))


t = int(input())
INF = 1e10
for i in range(t):
    n = int(input())
    mini = INF
    maxi = -INF
    for i in range(n):
        a, b = map(int, input().split())
        maxi = max(a, maxi)
        mini = min(b, mini)
    print(max(maxi - mini, 0))

t = int(input())
for T in range(t):
    n = int(input())
    arr = [tuple(map(int, input().split())) for i in range(n)]

    arr.sort(key=lambda x: x[1])
    a = arr[0][1]
    arr.sort(key=lambda x: -x[0])
    b = arr[0][0]

    if a <= b:
        print(b - a)
    else:
        print(0)


t = int(input())
for z in range(t):
    n = int(input())
    arr = []
    lr = 1000000000000
    rl = 0
    for i in range(n):
        l, r = list(map(int, input().split()))
        lr = min(lr, r)
        rl = max(rl, l)
        arr.append([l, r])
    ans = rl - lr
    if ans < 0:
        print(0)
    else:
        print(ans)


t = int(input())
for sadf in range(t):
    n = int(input())
    max_left = 0
    min_right = 1000000000001
    for i in range(n):
        a, b = map(int, input().split())
        max_left = max(max_left, a)
        min_right = min(min_right, b)
    print(max(0, max_left - min_right))

ans = []
n = int(input())

for _ in range(n):
    k = int(input())
    m_b, m_a = list(map(int, input().split()))
    for _ in range(k-1):
        a, b = list(map(int, input().split()))
        m_a = min(m_a, b)
        m_b = max(m_b, a)
    if (m_a>m_b):
        ans.append(0)
    else:
        ans.append(m_b-m_a)

for el in ans:
    print(el)


t = int(input())
for i1 in range(t):
    n = int(input())
    a, b = (0, 10**9)
    for i in range(n):
        c, d = list(map(int, input().split()))
        b = min(d, b)
        a = max(a, c)
    print(max(0, a - b))


t = int(input())
for i in range(t):
    n = int(input())
    r = 10 ** 9 + 1
    l = 0
    for i in range(n):
        x, y = map(int, input().split())
        r = min(r, y)
        l = max(x, l)
    print(max(0, l - r))

t = int(input())
for i in range(t):
    n = int(input());
    maxl, minr = list(map(int, input().split()))
    for j in range(1, n):
        l, r = list(map(int, input().split()))
        maxl = max(l, maxl)
        minr = min(r, minr);
    print(max(maxl - minr, 0))


t = int(input())
for i in range(t):
    la = []
    ra = []
    n = int(input())
    for j in range(n):
        l, r = list(map(int, input().split()))
        la.append(l)
        ra.append(r)
    x = max(la) - min(ra)
    if x < 0:
        x = 0
    print(x)


for _ in range(int(input())):
    n = int(input())
    data = []
    max_l = -1
    min_r = 10 ** 10
    for i in range(n):
        l, r = list(map(int, input().split()))
        max_l = max(max_l, l)
        min_r = min(min_r, r)
    print(max(max_l - min_r, 0))


t = int(input())
for i in range(t):
    n = int(input())
    a = []
    d = []
    for j in range(n):
        b, c = map(int, input().split())
        a.append(b)
        d.append(c)
    k1 = max(a)
    k2 = min(d)
    if k1 <= k2:
        print(0)
    else:
        print(k1 - k2)

n = int(input())
for i in range(n):
    k = int(input())
    l = 1000000000000
    r = 0
    for i in range(k):
        a, b = list(map(int, input().split()))
        if a>r:
            r = a
        if l>b:
            l = b
    if l >= r:
        print(0)
    else:
        print(r-l)


for i in range(int(input())):
    n = int(input())
    e = 10000000000000000
    s = -10000000000000000
    for i in range(n):
        a,b = map(int,input().split())
        e = min(e,b)
        s = max(a,s)
    print(max(0,s-e))

t=int(input())
for i in range(t):
    n=int(input())
    mi=10**100
    ma=0
    for j in range(n):
        a, b=[int(x) for x in input().split()]
        mi=min(mi, b)
        ma=max(a, ma)
    print(max(ma-mi,0))


from sys import stdin

t  = int(stdin.readline())
for q in range(t):
    n = int(stdin.readline())
    m1, m2 = 10**9+1, 0
    for i in range(n):
        l, r = list(map(int, stdin.readline().split()))
        m1 = min(m1, r)
        m2 = max(m2, l)
    print(max(0, m2 - m1))


t = int(input())
for i in range(t):
	n = int(input())
	leviy_otr = [10000000000,10000000000]
	pryavi_otr = [-10000000000,-10000000000]
	for j in range(n):
		a = input().split()
		a = [int(a[0]), int(a[1])]
		if leviy_otr[1] > a[1]:
			leviy_otr = a
		if pryavi_otr[0] < a[0]:
			pryavi_otr = a
	print (max(0, pryavi_otr[0] - leviy_otr[1]))

for _ in range(int(input())):
    n = int(input())
    a = []
    b = []
    for i in range(n):
        ai, bi = list(map(int, input().split()))
        a.append(ai)
        b.append(bi)
    if n == 1:
        print(0)
    else:
        if max(a) < min(b):
            print(0)
        else:
            print(max(a) - min(b))


a =  int(input())
Ans = []
for i in range(a):
    A = []
    x = int(input())
    B = []
    for j in range(x):
        n, m = list(map(int, input().split()))
        A.append(n)
        B.append(m)
    A.sort()
    B.sort()
    Ans.append(max(0, A[-1] - B[0]))
    #Ans.append(B[-1])
for b in Ans:
    print(b)


t = int(input())
for _ in range(t):
    n = int(input())
    first, last = 10**10, 0
    for i in range(n):
        l, r = [int(x) for x in input().split()]
        if r < first:
            first = r
        if l > last:
            last = l
    res = last - first
    if res >= 0:
        print(res)
    else:
        print(0)


# print(2**34)
t=int(input())
for i in range(t):
    n=int(input())
    ll=0
    rr=1000000001
    for j in range(n):
        l,r=list(map(int,input().split()))
        rr=min(r,rr)
        ll=max(l,ll)
    print(max(0,ll-rr))



test = int(input())
for _ in range(test):
    n = int(input())
    mas = 0
    minA = 10**10
    maxB = -1
    for __ in range(n):
        mas = list(map(int,input().split()))
        minA = min([minA,mas[1]])
        maxB = max([maxB,mas[0]])
    if maxB > minA:
        print(maxB-minA)
    else: print(0)