Famous wizard Sumar moonji kumaru is stuck in a huge room and has to save Hermione Granger from a monster. Kumaru is at location P1 given by integral coordinates (x_{1},y_{1}) and Hermione is at location P2 given by integral coordinates (x_{2},y_{2}). 
Sadly P1 and P2 are the only points at which floating rocks are present. Rest of the room is without floor and underneath is hot lava. 

Kumaru has to go from P1 to P2 but there are no floating rocks to walk on. Kumaru knows a spell that can make the rocks appear but only on the integral coordinates on the straight line joining P1 and P2.

How many rocks can appear at locations (x,y) on the line segment between P1 and P2 (excluding P1 and P2) which satisfy the condition that both x and y are integers?

Input Format 

The first line contains a single integer T, the number of test cases. T lines follow. 

 Each of the following T lines contains one test case each. Each test case contains 4 integers x_{1}, y_{1}, x_{2} and y_{2} separated by a single space. 

Output Format 

A single line containing the number of rocks.

Constraints 

1 <= T <= 10^{5} 

-10^{9} <= x_{1}, y_{1}, x_{2}, y_{2} <= 10^{9}

Sample input  

3
0 2 4 0
2 2 5 5
1 9 8 16

Sample Output

1
2
6

Explanation   

Case 1: As shown in the figure, between (0,2) and (4,0) there's only 1 integral point (2,1) hence 1 rock. 

Case 2: Between (2,2) and (5,5) lies (3,3) and (4,4), hence 2 rocks. 

Case 3: Between (1,9) and (8,16) there lies 6 rocks at positions (2,10) (3,11) (4,12) (5,13) (6,14) (7,15).

Difficulty: EASY

Solutions:
def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def CountPoints(x1, y1, x2, y2):
	p1 = abs(x2 - x1)
	q1 = abs(y2 - y1)
	g = gcd(p1, q1)
	return g - 1
T = int(input())
while T:
	T = T - 1
	(x1, y1, x2, y2) = input().split()
	x1 = int(x1)
	y1 = int(y1)
	x2 = int(x2)
	y2 = int(y2)
	print(CountPoints(x1, y1, x2, y2))


def gcd(a, b):
	if a > b:
		(a, b) = (b, a)
	while a > 0:
		(a, b) = (b % a, a)
	return b
T = int(input())
for _ in range(T):
	(x1, y1, x2, y2) = (int(_) for _ in input().split())
	print(gcd(abs(x2 - x1), abs(y2 - y1)) - 1)


from fractions import *
for _ in range(int(input())):
	(x1, y1, x2, y2) = [int(i) for i in input().split()]
	m = abs(y2 - y1)
	n = abs(x2 - x1)
	print(gcd(m, n) - 1)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
n = int(input())
sum = 0
for x in range(0, n):
	line = input().split()
	x1 = int(line[0])
	y1 = int(line[1])
	x2 = int(line[2])
	y2 = int(line[3])
	result = gcd(abs(x2 - x1), abs(y2 - y1)) - 1
	print(result)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
T = int(input())
for _ in range(T):
	(x1, y1, x2, y2) = [int(i) for i in input().split()]
	v = (abs(x2 - x1), abs(y2 - y1))
	print(gcd(v[0], v[1]) - 1)


c = int(input())

def coord(string):
	nros = string.split(' ')
	x = int(nros[0])
	y = int(nros[1])
	i = int(nros[2])
	j = int(nros[3])
	return (x, y, i, j)

def euclides(i, j):
	x = max(i, j)
	y = min(i, j)
	while y != 0:
		r = x % y
		x = y
		y = r
	return x

def rocas(string):
	xp = []
	yp = []
	(x1, y1, x2, y2) = coord(string)
	x3 = abs(x1 - x2)
	y3 = abs(y1 - y2)
	if min(x3, y3) == 0:
		return max(x3, y3) - 1
	piedras = euclides(x3, y3) - 1
	return piedras
for x in range(c):
	print(rocas(input()))


def gcd(m, n):
	while n > 0:
		r = m % n
		m = n
		n = r
	return m
T = int(input().strip())
for case in range(T):
	a = [0, 0]
	b = [0, 0]
	(a[0], a[1], b[0], b[1]) = map(int, input().strip().split())
	print(gcd(abs(b[1] - a[1]), abs(b[0] - a[0])) - 1)


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b != 0:
		(a, b) = (b, a % b)
	return a
t = int(input())
while t > 0:
	t -= 1
	l = list(map(int, input().split()))
	x1 = l[0]
	y1 = l[1]
	x2 = l[2]
	y2 = l[3]
	q = max(y1, y2)
	s = min(y1, y2)
	y = q - s - 1
	if x2 - x1 == 0:
		print(y)
		continue
	g = gcd(abs(y2 - y1), abs(x2 - x1)) - 1
	print(g)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return abs(a)
for _ in range(int(input())):
	(x1, y1, x2, y2) = map(int, input().split())
	print(gcd(x2 - x1, y2 - y1) - 1)


def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
t = int(input())
for i in range(t):
	(x1, y1, x2, y2) = input().split()
	(x1, y1, x2, y2) = (int(x1), int(y1), int(x2), int(y2))
	dx = abs(x1 - x2)
	dy = abs(y1 - y2)
	g = gcd(dx, dy)
	print(g - 1)


def GCD(a, b):
	return GCD(b, a % b) if b else a
t = int(input())
for _ in range(t):
	(a, b, x, y) = list(map(int, input().split()))
	x -= a
	y -= b
	x = abs(x)
	y = abs(y)
	g = GCD(x, y)
	print(g - 1)


import math

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

def main():
	for i in range(int(input())):
		(x1, y1, x2, y2) = input().split()
		(x1, y1, x2, y2) = (int(x1), int(y1), int(x2), int(y2))
		(a, b) = (math.fabs(x1 - x2), math.fabs(y1 - y2))
		print(int(gcd(a, b)) - 1)
main()


def hcf(a, b):
	while b % a != 0:
		(a, b) = (b % a, a)
	return a
t = int(input())
for i in range(t):
	(x1, y1, x2, y2) = [int(j) for j in input().split()]
	if x1 == x2:
		print(abs(y2 - y1) - 1)
		continue
	if y1 == y2:
		print(abs(x2 - x1) - 1)
		continue
	if abs(x2 - x1) < abs(y2 - y1):
		delta_y = abs(y1 - y2)
		delta_x = abs(x1 - x2)
		rem = delta_y % delta_x
		if rem == 0:
			print(delta_x - 1)
			continue
		gcd = hcf(rem, delta_x)
		mul = delta_x // gcd
		count = delta_x // mul
		if delta_x % mul == 0 and count > 0:
			count -= 1
		print(count)
	else:
		delta_y = abs(y1 - y2)
		delta_x = abs(x1 - x2)
		rem = delta_x % delta_y
		if rem == 0:
			print(delta_y - 1)
			continue
		gcd = hcf(rem, delta_y)
		mul = delta_y // gcd
		count = delta_y // mul
		if delta_y % mul == 0 and count > 0:
			count -= 1
		print(count)


def gcm(m, n):
	if m == n:
		return m
	if m > n:
		x = m % n
		if x == 0:
			return n
		elif x == 1:
			return 1
		else:
			return gcm(n, x)
	else:
		return gcm(n, m)
T = int(input())
for x in range(T):
	l = list(map(lambda x: int(x), input().split()))
	(x1, y1) = (l[0], l[1])
	(x2, y2) = (l[2], l[3])
	dx = abs(x1 - x2)
	dy = abs(y1 - y2)
	if dx == 0:
		print(dy - 1)
		continue
	if dy == 0:
		print(dx - 1)
		continue
	g = gcm(dx, dy)
	f = dx // g
	print(dx // f - 1)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(int(input())):
	(x1, y1, x2, y2) = map(int, input().split())
	print(gcd(abs(x2 - x1), abs(y2 - y1)) - 1)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
n_tests = int(input())
for t in range(n_tests):
	(x1, y1, x2, y2) = map(int, input().split())
	print(gcd(abs(x2 - x1), abs(y2 - y1)) - 1)


from fractions import Fraction
for _ in range(int(input())):
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == x2:
		print(abs(y1 - y2) - 1)
	elif y1 == y2:
		print(abs(x1 - x2) - 1)
	else:
		tg = Fraction(y1 - y2, x1 - x2)
		print(abs(x1 - x2) // tg.denominator - 1)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
for _ in range(t):
	(p1_x, p1_y, p2_x, p2_y) = map(int, input().split())
	(x, y) = (abs(p1_x - p2_x), abs(p1_y - p2_y))
	print(gcd(x, y) - 1)


def get_number_of_int_coordinates(x1, y1, x2, y2):
	(dx, dy) = (abs(x2 - x1), abs(y2 - y1))
	if dx == dy == 0:
		return 0
	elif dx == 0:
		return dy - 1
	elif dy == 0:
		return dx - 1
	gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
	return gcd(dx, dy) - 1
t = int(input())
for _ in range(t):
	(x1, y1, x2, y2) = [int(n) for n in input().split()]
	print(get_number_of_int_coordinates(x1, y1, x2, y2))


t = int(input())

def mod(x):
	if x < 0:
		x = -x
	return x

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
for k in range(t):
	(x1, y1, x2, y2) = input().split(' ')
	x1 = int(x1)
	y1 = int(y1)
	x2 = int(x2)
	y2 = int(y2)
	c = 0
	g = abs(gcd(x2 - x1, y2 - y1))
	print(g - 1)


def gcd(a, b):
	if a:
		return gcd(b % a, a)
	return b
for xx in range(int(input())):
	(a, b, x, y) = map(int, input().split())
	a = abs(a - x)
	b = abs(b - y)
	print(gcd(a, b) - 1)


n = int(input())
for i in range(n):
	(x1, y1, x2, y2) = map(int, input().split())
	A = abs(y2 - y1)
	B = abs(x2 - x1)
	if not A:
		print(B - 1)
		continue
	elif not B:
		print(A - 1)
		continue
	(a, b) = (A, B)
	while b:
		(a, b) = (b, a % b)
	nzv = B // a
	print(B // nzv - 1)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
for _ in range(int(input())):
	(x1, y1, x2, y2) = list(map(int, input().split()))
	print(gcd(abs(y2 - y1), abs(x2 - x1)) - 1)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input().strip())
for _ in range(t):
	(x1, y1, x2, y2) = [int(i) for i in input().strip().split()]
	print(abs(gcd(x2 - x1, y2 - y1)) - 1)


from math import sqrt

def gcd(a, b):
	while True:
		if a > b:
			r = a % b
			a = r
		else:
			r = b % a
			b = r
		if r == 0:
			return a * (a != 0) + b * (b != 0)
		if a < 0 or b < 0:
			return 1

def line_len(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def g(x1, y1, x2, y2):
	(rise, run) = (abs(y2 - y1), abs(x2 - x1))
	if rise == 0 or run == 0:
		return 1
	factor = gcd(rise, run)
	return line_len(0, 0, rise // factor, run // factor)
t = int(input())
for i in range(t):
	(x1, y1, x2, y2) = [int(x) for x in input().split()]
	(lng, shrt) = (line_len(x1, y1, x2, y2), g(x1, y1, x2, y2))
	print(round(lng / shrt) - 1)


def GCD(a, b):
	while a != b:
		if a > b:
			a = a - b
		else:
			b = b - a
	return a
T = int(input())
for i in range(0, T):
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == x2 and y1 == y2:
		print(0)
	elif x1 == x2:
		print(abs(y2 - y1) - 1)
	elif y1 == y2:
		print(abs(x2 - x1) - 1)
	else:
		gcd = GCD(abs(x2 - x1), abs(y2 - y1))
		print(gcd - 1)


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

def read_int():
	(v,) = read_ints()
	return v

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	if b == 0:
		return a
	return gcd(b, a % b)
T = read_int()
for t in range(T):
	(x1, y1, x2, y2) = read_ints()
	dx = abs(x1 - x2)
	dy = abs(y1 - y2)
	s = gcd(dx, dy)
	print(s - 1)


def gcd(a, b):
	if a > b:
		return gcd(b, a)
	if a == 0:
		return b
	return gcd(b % a, a)
t = int(input())
for _ in range(t):
	(x1, y1, x2, y2) = map(int, input().split())
	dx = abs(x2 - x1)
	dy = abs(y2 - y1)
	g = gcd(abs(x2 - x1), abs(y2 - y1))
	print(g - 1)


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


t = int(input().strip())

def gcd(a, b):
	if a > b:
		(a, b) = (b, a)
	while a:
		temp = a
		a = b % a
		b = temp
	return b
for _ in range(t):
	(a, b, x, y) = list(map(int, input().strip().split()))
	ans = gcd(abs(a - x), abs(b - y)) - 1
	print(ans)


import math
t = int(input())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
while t > 0:
	(x1, y1, x2, y2) = [int(x) for x in input().split(' ')]
	print(gcd(abs(x2 - x1), abs(y2 - y1)) - 1)
	t -= 1


n = int(input())

def gcd(a, b):
	if not b:
		return a
	return gcd(b, a % b)
while n:
	n -= 1
	(x1, y1, x2, y2) = (int(x) for x in input().split(' '))
	w = abs(x1 - x2)
	h = abs(y1 - y2)
	if w == 0:
		print(max(h - 1, 0))
	elif h == 0:
		print(max(w - 1, 0))
	else:
		x = gcd(w, h)
		print(x - 1)


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


t = int(input())

def GCD(a, b):
	if b == 0:
		return a
	return GCD(b, a % b)
for _ in range(t):
	(a, b, x, y) = map(int, input().split())
	a = abs(a - x)
	b = abs(b - y)
	print(GCD(a, b) - 1)


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	(x1, y1, x2, y2) = map(int, input().split())
	x = abs(x1 - x2)
	y = abs(y1 - y2)
	print(gcd(x, y) - 1)


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


def gcd(a, b):
	while b != 0:
		t = b
		b = a % b
		a = t
	return a
t = int(input().strip())
for _ in range(t):
	(a, b, x, y) = [int(temp) for temp in input().strip().split(' ')]
	dx = abs(x - a)
	dy = abs(y - b)
	if dx == 0 and dy == 0:
		print(0)
	else:
		g = gcd(dx, dy)
		print(g - 1)


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


import fractions
for i in range(int(input())):
	(x1, y1, x2, y2) = input().strip().split()
	(x1, y1, x2, y2) = (int(x1), int(y1), int(x2), int(y2))
	if x1 == x2 or y1 == y2:
		x = max(abs(y2 - y1), abs(x2 - x1)) - 1
		print(0 if x == -1 else x)
	else:
		m = fractions.Fraction(y2 - y1, x2 - x1)
		x = m.denominator
		print(abs((x2 - x1) // x) - 1)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
n = int(input())
for i in range(n):
	(x1, y1, x2, y2) = list(map(int, input().split()))
	print(gcd(abs(x2 - x1), abs(y2 - y1)) - 1)


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


gcd = lambda x, y: gcd(y, x) if x > y else y if x == 0 else gcd(y % x, x) if y % x else x
print('\n'.join(map(lambda x, y, s, t: str(gcd(abs(x - s), abs(y - t)) - 1), *zip(*(map(int, input().split()) for _ in range(int(input())))))))


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def calculate():
	T = int(input().strip())
	for i in range(T):
		(x1, y1, x2, y2) = [int(x) for x in input().split()]
		X = abs(x2 - x1)
		Y = abs(y2 - y1)
		result = gcd(X, Y) - 1
		print(result)
calculate()


import sys

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def solve(x1, y1, x2, y2):
	dx = abs(x1 - x2)
	dy = abs(y1 - y2)
	print('dx=%d dy=%d' % (dx, dy), file=sys.stderr)
	if dx == 0 and dy == 0:
		return 0
	if dx == 0:
		return dy - 1
	if dy == 0:
		return dx - 1
	if dx == dy:
		return dx - 1
	g = gcd(dx, dy)
	return g - 1
t = int(input())
for _ in range(t):
	(x1, y1, x2, y2) = map(int, input().split())
	print(solve(x1, y1, x2, y2))


import sys
lines = sys.stdin.readlines()[1:]

def nwd(a, b):
	if a < b:
		(a, b) = (b, a)
	if b == 0:
		return a
	return nwd(b, a % b)
for line in lines:
	line = line.split(' ')
	x1 = int(line[0])
	y1 = int(line[1])
	x2 = int(line[2])
	y2 = int(line[3])
	if x1 == x2:
		print(abs(y1 - y2) - 1)
	else:
		print(nwd(abs(x1 - x2), abs(y1 - y2)) - 1)


def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a
T = int(input().strip())
for t in range(T):
	[x1, y1, x2, y2] = [int(i) for i in input().strip().split()]
	dx = max(x1, x2) - min(x1, x2)
	dy = max(y1, y2) - min(y1, y2)
	if x1 == x2:
		print(dy - 1)
	elif y1 == y2:
		print(dx - 1)
	else:
		print(gcd(dx, dy) - 1)


def gcd(a, b):
	(a, b) = (abs(a), abs(b))
	(a, b) = a > b and (a, b) or (b, a)
	while b > 0:
		(a, b) = (b, a % b)
	return a
T = int(input().strip())
for _ in range(T):
	(x1, y1, x2, y2) = list(map(int, input().strip().split()))
	print(gcd(x2 - x1, y2 - y1) - 1)