Chef has a new customer and he wants to prepare his order as soon as possible. While preparing, he sees that the mint sauce is finished. He has to run upstairs to get it from other kitchen. Chef is currently on the X^{th} stair. He has to climb all the way up to the Y^{th} stair in minimum number of steps. In one step, Chef can do one of the following things: 

Climb a single stair. ( i.e go from the X^{th} stair to the (X+1)^{th} stair. ) 
Climb two stairs only if the final stair falls at a prime number position. ( i.e. go from the X^{th} stair to the (X+2)^{th} stair, only if (X + 2) is a prime number) 

Help Chef reach the Y^{th} stair from the X^{th} stair in minimum number of steps. 

\textbf{See Explanation for more clarity.}

Note: The input files are large. The use of Fast I/O is recommended.

------ Input Format ------ 

- The first line contains an integer T denoting the number of test cases. The T test cases then follow.
- The first line of each test case contains X and Y denoting the starting stair and ending stair respectively.

------ Output Format ------ 

- Output a single integer representing minimum number of steps chef can take to reach from X^{th} to Y^{th} stair.

------ Constraints ------ 

$1 ≤ T ≤ 10^{6}$
$1 ≤ X < Y ≤ 10^{7}$

----- Sample Input 1 ------ 
4
2 10
5 12
34 43
57 63
----- Sample Output 1 ------ 
6
5
6
4
----- explanation 1 ------ 
Test case $1$: Chef starts from $2^{nd}$, goes to $3^{rd}$ stair, then to $5^{th}$ stair as $5$ or $(3+2)$ is prime number. Now, from $5^{th}$ stair, Chef goes to $7^{th}$ stair as $7$ or $(5+2)$ is a prime number, then Chef goes to $8^{th}$ stair, then to $9^{th}$ stair and finally to $10^{th}$ stair. This approach takes a total of $6$ steps which is the minimum possible number of steps Chef can take to reach the $10^{th}$ stair starting from the $2^{nd}$ stair. 

Test case $3$: Starting from the $34^{th}$ stair, Chef moves through the stairs as following. $34$ → $35$ → $37$ → $38$ → $39$ → $41$ → $43$.

Difficulty: HARD

Solutions:
import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
pr = lambda x: x

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

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

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

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

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

def SieveOfEratosthenes(n):
	Z = []
	prime = [1 for i in range(n + 1)]
	p = 2
	prime[0] = prime[1] = 0
	while p * p <= n:
		if prime[p] == 1:
			for i in range(p * p, n + 1, p):
				prime[i] = 0
		p += 1
	return prime
pri = list(accumulate(SieveOfEratosthenes(10000010)))
for i in range(int(input())):
	(x, y) = map(int, input().split())
	ans = y - x
	if x == y:
		print(0)
	elif y == x + 1:
		print(1)
	else:
		primes = pri[y] - pri[x + 1]
		ans -= primes
		print(ans)


from itertools import accumulate

def generate_primes(n):
	primes = [True for x in range(n + 1)]
	num = 2
	while num * num <= n:
		if primes[num]:
			for i in range(num ** 2, n + 1, num):
				primes[i] = False
		num += 1
	primes[0] = False
	primes[1] = False
	return primes
t = int(input().strip())
primes = list(accumulate(generate_primes(10 ** 7 + 1)))
while t > 0:
	t -= 1
	(x, y) = map(int, input().strip().split())
	if x == y:
		print(0)
	elif x + 1 == y:
		print(1)
	else:
		steps = y - x - (primes[y] - primes[x + 1])
		print(steps)


from itertools import accumulate

def makeIsPr(p_limit):
	track = [False, True] * (p_limit // 2 + 1)
	if p_limit % 2 == 0:
		track.pop()
	track[0:3] = [False, False, True]
	pc = 3
	while pc * pc <= p_limit:
		if track[pc]:
			for a in range(pc * pc, p_limit + 1, 2 * pc):
				track[a] = False
		pc += 2
	return track
pCount = list(accumulate(makeIsPr(10 ** 7)))
for _ in range(int(input())):
	(S, E) = map(int, input().split())
	print(E - S - (pCount[E] - pCount[S + 1]))


def main():
	primes = [1] * 10000001
	for i in range(2, 10002):
		if primes[i] == 1:
			for j in range(i + i, 10000001, i):
				primes[j] = 0
	primes[0] = 0
	primes[1] = 0
	for i in range(1, len(primes)):
		primes[i] = primes[i] + primes[i - 1]
	for _ in range(int(input())):
		(X, Y) = map(int, input().split())
		c = Y - X
		n = primes[Y] - primes[X + 1]
		print(c - n)
main()


from itertools import groupby, accumulate

def solve():

	def SieveOfEratosthenes(n):
		Z = []
		prime = [1 for i in range(n + 1)]
		p = 2
		prime[0] = prime[1] = 0
		while p * p <= n:
			if prime[p] == 1:
				for i in range(p * p, n + 1, p):
					prime[i] = 0
			p += 1
		return prime
	pri = list(accumulate(SieveOfEratosthenes(10000010)))
	for i in range(int(input())):
		(x, y) = map(int, input().split())
		ans = y - x
		if x == y:
			print(0)
		elif y == x + 1:
			print(1)
		else:
			primes = pri[y] - pri[x + 1]
			ans -= primes
			print(ans)
solve()


from sys import stdin
from itertools import accumulate

def makeIsPr(p_limit):
	track = [False, True] * (p_limit // 2 + 1)
	if p_limit % 2 == 0:
		track.pop()
	track[0:3] = [False, False, True]
	pc = 3
	while pc * pc <= p_limit:
		if track[pc]:
			for a in range(pc * pc, p_limit + 1, 2 * pc):
				track[a] = False
		pc += 2
	return track
lim = 10000000
isPrime = makeIsPr(lim)
pCount = list(accumulate(isPrime))
inp = stdin.readline
T = int(inp())
ans = []
for _ in range(T):
	(S, E) = map(int, inp().split())
	ans.append(E - S - (pCount[E] - pCount[S + 1]))
print(*ans, sep='\n')


import sys
import bisect
input = sys.stdin.readline

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

def solve():
	(a, b) = map(int, input().split())
	ans = b - a
	(l, r) = (bisect.bisect_left(primes, a + 2), bisect.bisect_left(primes, b))
	ans -= r - l
	if len(primes) != r and primes[r] == b:
		ans -= 1
	print(ans)
t = int(input())
primes = SieveOfEratosthenes(10 ** 7)
for _ in range(t):
	solve()


a = int(input())
MAX = 10000000
prefix = [0] * (MAX + 1)

def buildPrefix():
	prime = [1] * (MAX + 1)
	p = 2
	while p * p <= MAX:
		if prime[p] == 1:
			i = p * 2
			while i <= MAX:
				prime[i] = 0
				i += p
		p += 1
	for p in range(2, MAX + 1):
		prefix[p] = prefix[p - 1]
		if prime[p] == 1:
			prefix[p] += 1

def query(L, R):
	return prefix[R] - prefix[L - 1]
buildPrefix()
for i in range(a):
	b = list(map(int, input().split()))
	rnum = b[-1] - b[0] + 1
	print(rnum - query(b[0] + 2, b[-1]) - 1)


from sys import stdin, stdout
from math import ceil, sqrt
from bisect import bisect_left

def sieve(MAXN):
	is_prime[0] = is_prime[1] = 0
	for i in range(4, MAXN, 2):
		is_prime[i] = 0
	for i in range(3, ceil(sqrt(MAXN)), 2):
		if is_prime[i]:
			for j in range(i * i, MAXN + 1, i * 2):
				is_prime[j] = 0
	primes.append(2)
	for i in range(3, MAXN, 2):
		if is_prime[i]:
			primes.append(i)
N = int(10000000.0 + 10)
primes = []
is_prime = [1 for _ in range(N)]
sieve(N)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(t1, t2) = (bisect_left(primes, y + 1), bisect_left(primes, x + 1))
	ans = y - x + t2 - t1
	if x + 1 == primes[t2]:
		ans += 1
	print(ans)


import math as m
from itertools import accumulate

def Sieve(n):
	isPrime = [True] * (n + 1)
	isPrime[0] = isPrime[1] = False
	for i in range(2, int(m.sqrt(n))):
		if isPrime[i]:
			for j in range(2 * i, n + 1, i):
				isPrime[j] = False
	return isPrime
prim = Sieve(int(10000000.0) + 3)
tot_prim_nums = list(accumulate(prim))
t = int(input())
while t:
	(x, y) = map(int, input().split())
	ans = tot_prim_nums[y] - tot_prim_nums[x + 1]
	print(y - x - ans)
	t -= 1


import sys
from math import sqrt, ceil, floor, gcd
from collections import Counter
input = lambda : sys.stdin.readline()

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

def str_arr():
	return list(map(str, input().split()))

def get_str():
	return map(str, input().split())

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

def get_flo():
	return map(float, input().split())

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

def generatePrime(n):
	prime = [1 for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p ** 2, n + 1, p):
				prime[i] = 0
		p += 1
	(prime[0], prime[1]) = (0, 0)
	for i in range(1, len(prime)):
		prime[i] += prime[i - 1]
	return prime
prime = generatePrime(10000008)

def solve(a, b):
	if a + 2 <= b:
		print(b - a - (prime[b] - prime[a + 1]))
	else:
		print(b - a)
for _ in range(int(input())):
	(a, b) = get_int()
	solve(a, b)


import sys
import bisect

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

def in1():
	return int(input())

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
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
a = []
SieveOfEratosthenes(10000000)
for _ in range(in1()):
	(x, y) = get_line()
	xr = bisect.bisect_right(a, x)
	yr = bisect.bisect_right(a, y) - 1
	y_minus_x = y - x
	diff_of_yr_xr = yr - xr + 1
	if a[xr] - x < 2:
		diff_of_yr_xr -= 1
	print(y_minus_x - diff_of_yr_xr)


from itertools import accumulate

def sieve_of_erothstenes(y):
	primes = [True] * (y + 1)
	primes[0] = primes[1] = False
	s = 2
	while s * s <= y:
		if primes[s]:
			for i in range(s * s, y + 1, s):
				primes[i] = False
		s += 1
	return primes
primes = list(accumulate(sieve_of_erothstenes(int(10000000.0 + 1))))
t = int(input())
while t:
	t -= 1
	(x, y) = map(int, input().strip().split())
	ans = y - x
	if x == y:
		print(0)
	elif y == x + 1:
		print(1)
	else:
		num_of_primes = primes[y] - primes[x + 1]
		ans -= num_of_primes
		print(ans)


def sieve_of_eratosthenes(n):
	arr = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if arr[p]:
			for i in range(p ** 2, n + 1, p):
				arr[i] = False
		p += 1
	arr[0] = False
	arr[1] = False
	count = 0
	prime_count = [0, 0]
	for i in range(2, n + 1):
		if arr[i]:
			count += 1
		prime_count.append(count)
	return prime_count
x_inputs = []
y_inputs = []
y_max = -1
t = int(input())
for i in range(0, t):
	(x, y) = map(int, input().split())
	x_inputs.append(x)
	y_inputs.append(y)
	if y > y_max:
		y_max = y
primes = sieve_of_eratosthenes(y_max)
for i in range(0, t):
	in_between_primes = primes[y_inputs[i]] - primes[x_inputs[i] + 1]
	steps = y_inputs[i] - x_inputs[i] - in_between_primes
	print(steps)


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(fast())
sys.setrecursionlimit(10 ** 6)
sieve = [True] * 10000009
sievenumstore = []

def dosievestuff():
	p = 2
	n = 10000009
	while p * p <= n:
		if sieve[p] == True:
			for i in range(p * p, n + 1, p):
				if i >= n:
					break
				sieve[i] = False
		p += 1
	for i in range(2, len(sieve)):
		if sieve[i]:
			sievenumstore.append(i)

def binarysearchcustom(num):
	low = 0
	high = len(sievenumstore)
	temp = -1
	while low < high:
		mid = low + (high - low) // 2
		if sievenumstore[mid] <= num:
			temp = mid
			low = mid + 1
		else:
			high = mid
	return temp
dosievestuff()
for _ in range(test_case):
	(x, y) = [int(_) for _ in fast().split()]
	intial = bisect.bisect_right(sievenumstore, x)
	lastindex = binarysearchcustom(y)
	if lastindex == -1:
		lastindex = len(sievenumstore)
	maximumjumppossible = y - x
	if abs(x - sievenumstore[intial]) > 1:
		intial -= 1
	print(maximumjumppossible - (lastindex - intial))


import io, os, time, math
from sys import stdin, stdout
from bisect import bisect_right as br, bisect_left as bl

def take_input():
	return stdin.readline()

def display_arr(arr):
	stdout.write(' '.join(map(str, arr)) + '\n')

def display_num(num):
	stdout.write(str(num) + '\n')

def sieve():
	prime = [1] * high
	p = 2
	while p * p < high:
		if prime[p] == 1:
			i = p * p
			while i < high:
				prime[i] = 0
				i += p
		p += 1
	for p in range(2, high):
		prefix[p] = prefix[p - 1]
		if prime[p] == 1:
			prefix[p] += 1

def query(l, r):
	return prefix[r] - prefix[l - 1]
high = 10 ** 7 + 1
prefix = [0] * high
sieve()
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	p_c = query(x + 2, y)
	diff = y - x
	print(diff - p_c)


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(fast())
sys.setrecursionlimit(10 ** 6)
sieve = [True] * 10000009
helper = []

def dosieve():
	p = 2
	n = 10000009
	while p * p <= n:
		if sieve[p] == True:
			for i in range(p * p, n + 1, p):
				if i >= n:
					break
				sieve[i] = False
		p += 1
	for i in range(2, len(sieve)):
		if sieve[i]:
			helper.append(i)

def binary(num):
	low = 0
	high = len(helper)
	temp = -1
	while low < high:
		mid = low + (high - low) // 2
		if helper[mid] <= num:
			temp = mid
			low = mid + 1
		else:
			high = mid
	return temp

def ans():
	(x, y) = [int(_) for _ in fast().split()]
	intial = bisect.bisect_right(helper, x)
	last = binary(y)
	if last == -1:
		last = len(helper)
	maxi = y - x
	if abs(x - helper[intial]) > 1:
		intial -= 1
	print(maxi - (last - intial))
	return
dosieve()
for _ in range(test_case):
	ans()


def calprimes(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
	primes = []
	for p in range(2, n + 1):
		if prime[p]:
			primes.append(p)
	return primes
import bisect
primes = calprimes(10000001)
t = int(input())
for t in range(t):
	(x, y) = [int(x) for x in input().split()]
	ans = y - x - (bisect.bisect(primes, y) - bisect.bisect(primes, x)) + 1 * (primes[bisect.bisect(primes, x)] - x == 1)
	print(ans)