The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.

There are $a$ programmers and $b$ mathematicians at Berland State University. How many maximum teams can be made if:

each team must consist of exactly $4$ students,

teams of $4$ mathematicians or $4$ programmers are unlikely to perform well, so the decision was made not to compose such teams.

Thus, each team must have at least one programmer and at least one mathematician.

Print the required maximum number of teams. Each person can be a member of no more than one team.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases.

This is followed by descriptions of $t$ sets, one per line. Each set is given by two integers $a$ and $b$ ($0 \le a,b \le 10^9$).


-----Output-----

Print $t$ lines. Each line must contain the answer to the corresponding set of input data — the required maximum number of teams.


-----Examples-----

Input
6
5 5
10 1
2 3
0 0
17 2
1000000000 1000000000
Output
2
1
1
0
2
500000000


-----Note-----

In the first test case of the example, two teams can be composed. One way to compose two teams is to compose two teams of $2$ programmers and $2$ mathematicians.

In the second test case of the example, only one team can be composed: $3$ programmers and $1$ mathematician in the team.

Difficulty: EASY
Tags: Sorting

Mathematics

Constructive algorithms
Skill types: Sorting

Starter code:

Solutions:
for s in [*open(0)][1:]:
	(a, b) = sorted(map(int, s.split()))
	print(a + min(b, 3 * a) >> 2)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	print(min((a + b) // 4, a, b))


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
from random import randint
import math
import sys
sys.setrecursionlimit(10 ** 6)

def foo(a, b):
	if a >= 3 * b or b >= 3 * a:
		return min(a, b)
	return (a + b) // 4
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(foo(a, b))


import sys
for _ in range(int(sys.stdin.readline())):
	(a, b) = map(int, sys.stdin.readline().split())
	res = min((a + b) // 4, min(a, b))
	print(res)


for s in [*open(0)][1:]:
	(n, m) = map(int, s.split())
	print(min((n + m) // 4, n, m))


def solve(t):
	data = [list(map(int, input().split())) for i in range(t)]
	commands_amo = [''] * t
	for i in range(t):
		if data[i][0] == data[i][1]:
			commands_amo[i] = str(data[i][0] // 2)
		elif min(data[i]) < sum(data[i]) // 4:
			commands_amo[i] = str(min(data[i]))
		else:
			commands_amo[i] = str(sum(data[i]) // 4)
	return '\n'.join(commands_amo)
print(solve(int(input())))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	ans = (a + b) // 4
	ans = min(a, b, ans)
	print(ans)


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

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

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

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

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
inf = 4294967295
md = 998244353

def solve():
	(a, b) = LI()
	ans = min((a + b) // 4, a, b)
	print(ans)
for testcase in range(II()):
	solve()


from sys import stdin, stdout
import sys
import math
import itertools
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
import re

def main():
	t = int(stdin.readline().strip())
	for j in range(1, t + 1):
		(a, b) = map(int, stdin.readline().strip().split())
		pos = min(a, b)
		if a + b >= pos * 4:
			ans = pos
		else:
			ans = (a + b) // 4
		print(ans)
main()


t = int(input())
res = []
for i in range(t):
	(a, b) = map(int, input().split())
	max_n = (a + b) // 4
	if a < max_n:
		res.append(a)
	elif b < max_n:
		res.append(b)
	else:
		res.append(max_n)
for r in res:
	print(r)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
tc = 1
tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	if a + b >= 4:
		print(min(a, b, (a + b) // 4))
	else:
		print(0)


import sys

def solve(a, b):
	if a == 0 or b == 0:
		print(0)
	elif a == b:
		print((a + b) // 4)
	else:
		if a > b:
			ans = min((a + b) // 4, b)
		else:
			ans = min((a + b) // 4, a)
		print(ans)

def main():
	test_case = int(sys.stdin.readline())
	for tc in range(test_case):
		(a, b) = map(int, sys.stdin.readline().split())
		solve(a, b)
main()


import sys
import bisect
import math
input = lambda : sys.stdin.readline().strip()
mod = 10 ** 9 + 9

def solve():
	(a, b) = map(int, input().split())
	m = min(a, b)
	(a, b) = (a - m, b - m)
	x = (a + b) // 2
	if m <= x:
		return m
	else:
		y = m - x
		return x + y // 2
t = 1
t = int(input())
for _ in range(t):
	print(solve())


t = int(input())
list1 = []
for i in range(t):
	list1.append([int(x) for x in input().split()])
for i in range(t):
	print(min(list1[i][0], list1[i][1], sum(list1[i]) // 4))


import sys

def f(l, n, f):
	a = 0
	x = n - 1
	while a <= x:
		m = a + (x - a) // 2
		if l[m] == f:
			return m
		elif l[m] > f:
			x = m - 1
		else:
			a = m + 1
	return None
for i in range(int(sys.stdin.readline())):
	(a, b) = map(int, sys.stdin.readline().split())
	t = (a + b) // 4
	if min(a, b) >= t:
		print(t)
	else:
		print(min(a, b))


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	print(min((x + y) // 4, min(x, y)))


import sys
for _ in range(int(sys.stdin.readline().strip())):
	(a, b) = map(int, sys.stdin.readline().split())
	ans = (a + b) // 4
	if ans > a or ans > b:
		ans = min(a, b)
	sys.stdout.write(str(ans) + '\n')


from sys import stdin
input = stdin.readline

def can(m, a, b):
	mini = min(a, b)
	maxi = max(a, b)
	if m <= mini and maxi - 2 * m >= 0:
		return True
	return False

def maxteams(a, b):
	lb = 0
	ub = 1000000000
	while lb <= ub:
		mid = lb + (ub - lb) // 2
		if can(mid, a, b):
			if can(mid + 1, a, b) == False:
				return mid
			else:
				lb = mid + 1
		else:
			ub = mid - 1
	return 0
for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	print(min((a + b) // 4, min(a, b)))


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
mod = 10 ** 9 + 7
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(min(a, b, (a + b) // 4))


def cal(x, y):
	if x >= 3 * y or y >= 3 * x:
		return min(x, y)
	else:
		return (x + y) // 4
n = input()
output = []
for i in range(int(n)):
	(x, y) = map(int, input().split())
	output.append(str(cal(int(x), int(y))))
print('\n'.join(output))


def team(a, b):
	return min((a + b) // 4, a, b)
x = int(input())
m = []
for i in range(x):
	z = input()
	z1 = z.split(' ')
	z2 = [int(t) for t in z1]
	m.append(z2)
for j in range(x):
	print(team(m[j][0], m[j][1]))


number = int(input())
final = []
for i in range(0, number):
	pm = input()
	pm = pm.split()
	for i in range(len(pm)):
		pm[i] = int(pm[i])
	p = pm[0]
	m = pm[1]
	small = 0
	big = 0
	mini = 0
	if p < m:
		small = p
		big = m
	else:
		small = m
		big = p
	mini = min((small + big) // 4, small)
	final.append(mini)
for i in range(len(final)):
	final[i] = str(final[i])
final = '\n'.join(final)
print(final)


r = int(input())
num = []
for i in range(r):
	num.append(input().split())
for i in range(r):
	a = int(num[i][0])
	b = int(num[i][1])
	print(min(a, b, (a + b) // 4))


import sys
input = sys.stdin.readline
M = 1000000007

def solve():
	(a, b) = map(int, input().split())
	return min(a, b, (a + b) // 4)
for _ in range(int(input())):
	print(solve())


def solver(a, b):
	result = 0
	sum_val = a + b
	offset = 4
	if a > b:
		lower_val = b
		higher_val = a
	elif a < b:
		lower_val = a
		higher_val = b
	else:
		counter_2 = a // 2
		return int(counter_2)
	if sum_val < offset:
		return 0
	if higher_val >= lower_val * 3:
		return lower_val
	return sum_val // 4
res_list = []
count_t = int(input())
for i in range(count_t):
	(a, b) = map(int, input().split())
	res = solver(a, b)
	res_list.append(res)
for i in res_list:
	print(i)


k = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if (a + b) // 4 < a and (a + b) // 4 < b:
		k.append((a + b) // 4)
	else:
		k.append(min(a, b))
for t in k:
	print(t)


for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	print(min(a, b, (a + b) // 4))


from sys import stdin

def solve():
	results = []
	for _ in range(int(stdin.readline().strip())):
		(a, b) = map(int, stdin.readline().rstrip().split())
		c = min(a, b)
		ans = min((a + b) // 4, c)
		results.append(ans)
	print('\n'.join(map(str, results)))
solve()


t = int(input())
salida = list()
for i in range(t):
	aux = input().split()
	a = 0.0
	b = 0.0
	if int(aux[0]) >= int(aux[1]):
		a = int(aux[0])
		b = int(aux[1])
	else:
		a = int(aux[1])
		b = int(aux[0])
	if b == 0 or a + b < 4:
		salida.append(0)
	elif a == b:
		salida.append(b // 2)
	elif a >= 3 * b:
		salida.append(b)
	else:
		salida.append(int((a - b) / 2 + (3 * b - a) / 4))
for s in salida:
	print(s)


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
from random import randint
import math
import sys
sys.setrecursionlimit(10 ** 6)

def foo(a, b):
	if a < b:
		(a, b) = (b, a)
	if a == 0 or b == 0 or a + b < 4:
		return 0
	if a + b == 4:
		return 1
	if a >= 3 * b or b >= 3 * a:
		return min(a, b)
	if a == b:
		return a // 2
	diff = a - b
	steps = (a - b) // 2
	if steps != 0:
		return steps + foo(a - 3 * steps, b - steps)
	elif b > 100:
		z = (b - 10) // 2
		return z + foo(a - 2 * z, b - 2 * z)
	else:
		return 1 + foo(a - 3, b - 1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	try:
		print(foo(a, b))
	except:
		print(str(a) + '-' + str(b))


n_of_inputs = int(input())
teams = [map(int, input().split()) for _ in range(n_of_inputs)]
for team in teams:
	team = sorted(team, reverse=True)
	if team[1] * 3 <= team[0]:
		print(team[1])
	elif team[0] - team[1] < 2:
		print(team[1] // 2)
	else:
		x = (team[1] - team[0]) // -2
		team[0] -= x * 3
		team[1] -= x
		print(x + team[1] // 2)


arr = []
for i in range(int(input())):
	arr.append(list(map(int, input().split())))
for a in arr:
	if min(a) < 1:
		print(0)
	else:
		print(min(sum(a) // 4, min(a)))


t = int(input(''))
x = []
for i in range(t):
	x.append(input('').split())
for i in x:
	a = int(i[0])
	b = int(i[1])
	n = (a + b) // 4
	if a < n:
		n = a
	if b < n:
		n = b
	print(n)


t = int(input(''))
res = []
for i in range(t):
	(a, b) = input('').split()
	a = int(a)
	b = int(b)
	n = (a + b) // 4
	if a < n:
		n = a
	if b < n:
		n = b
	res.append(n)
for i in res:
	print(i)


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
mem = {}
for t in wtf[1:]:
	(a, b) = map(int, t.split())
	c = (a + b) // 4
	d = min(a, b)
	print(c if c <= d else d)
	continue
	if a == b:
		print(a // 2)
	else:
		c = max(a, b)
		d = min(a, b)
		(q, r) = divmod(c, 3)
		ans = 0
		for i in range(q + 1):
			print(a, b, c, d, q, r)
			if d <= q:
				ans = d
				break
			(Q, R) = divmod(d - q, 3)
			if R == 0:
				ans = q + Q
				break
			r += 3
			q -= 1
		print(ans)


import sys
input = sys.stdin.read()
input = input.strip().split('\n')
for line in input[1:]:
	group = line.split(' ')
	m = int(group[0])
	p = int(group[1])
	if m == 0 or p == 0:
		print(0)
	else:
		total = m + p
		smallest = min(m, p)
		print(min(smallest, total // 4))


t = int(input())
for i in range(t):
	(m, p) = map(int, input().split())
	if m // 3 > p:
		print(p)
	elif p // 3 > m:
		print(m)
	else:
		print((m + p) // 4)


for i in range(int(input())):
	(coders, pros) = map(int, input().split())
	if coders * 3 >= pros and pros * 3 >= coders:
		print((coders + pros) // 4)
	else:
		print(min(pros, coders))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	s = 0
	if b > a:
		(a, b) = (b, a)
	s = (a + b) // 4
	if s > b:
		print(b)
	else:
		print(s)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	num = (a + b) // 4
	print(min(a, b, num))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		if a >= 3 * b:
			print(b)
		else:
			print(int((3 * b - a) / 4 + (a - b) / 2))
	elif 3 * a <= b:
		print(a)
	else:
		print(int((3 * a - b) / 4 + (b - a) / 2))


def func(a, b):
	tt = (a + b) // 4
	if tt <= a and tt <= b:
		return tt
	elif tt <= a:
		return b
	else:
		return a
for t in range(int(input())):
	(a, b) = map(int, input().split())
	print(func(a, b))


def main():
	t = int(input())
	for _ in range(0, t):
		(a, b) = map(int, input().split(' '))
		print(min(a, min(b, int((a + b) / 4))))
main()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	mini = min(a, b)
	maxi = max(a, b)
	if maxi >= 3 * mini:
		ans = mini
	else:
		ans = (a + b) // 4
	print(ans)


x = int(input())
while x != 0:
	(c, d) = map(int, input().split())
	val = min(int((c + d) / 4), c, d)
	print(val)
	x = x - 1


t = int(input())
for _ in range(t):
	a = input().strip().split(' ')
	p = int(a[0])
	m = int(a[1])
	ans = 0
	t = (p + m) // 4
	if p <= t:
		ans = p
	elif m <= t:
		ans = m
	else:
		ans = t
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	teams = (a + b) // 4
	if teams <= a and teams <= b:
		print(teams)
	else:
		print(min(a, b))


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	s1 = (m + n) // 4
	s2 = min(m, n)
	if s1 < s2:
		print(s1)
	else:
		print(s2)


for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	if a * 3 >= b:
		print((a + b) // 4)
	else:
		print(a)


for x in range(int(input())):
	(p, q) = list(map(int, input().split()))
	print(min((p + q) // 4, min(p, q)))


t = int(input())
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	p = (a + b) // 4
	print(min(a, b, p))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	n = (a + b) // 4
	if a == b:
		print(n)
	elif a < b and a >= n:
		print(n)
	elif a < b and a < n:
		print(a)
	elif b < a and b >= n:
		print(n)
	elif b < a and b < n:
		print(b)


import math
answers = []
ans = 0
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = a
	if a > b:
		c = b
		b = a
		a = c
	ost = a + b
	if (b - a) // 2 > a:
		ans += a
		a = 0
		b = b - 3 * a
	else:
		ans += (b - c) // 2
		a -= (b - c) // 2
		b -= (b - c) // 2 * 3
	c = a
	ans_c = min(c // 2, b // 2)
	a -= min(c // 2, b // 2) * 2
	b -= min(c // 2, b // 2) * 2
	ans = ans_c + ans
	answers.append(ans)
	ans = 0
for i in range(n):
	print(answers[i])


t = int(input())
for _ in range(t):
	k = input().split(' ')
	x = int(k[0])
	y = int(k[1])
	tam = int((x + y) / 4)
	if x == y:
		print(int(x / 2))
	elif x < y:
		if tam < x:
			print(tam)
		else:
			print(x)
	elif tam < y:
		print(tam)
	else:
		print(y)


t = int(input())
for i in range(t):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	print(min(min(a, b), (a + b) // 4))


n = int(input())

def solve(a, b):
	if a == 0 or b == 0:
		return 0
	tmpA = a
	if b > a:
		a = b
		b = tmpA
	return min(b, (a + b) // 4)
while n > 0:
	(a, b) = list(map(int, input().split(' ')))
	print(solve(a, b))
	n -= 1


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	x = int((a + b) / 4)
	if x > b:
		x = b
	elif x > a:
		x = a
	if x < 1:
		print(0)
	else:
		print(x)


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	print(min(a, b, (a + b) // 4))


import math

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

def stringlsit():
	return input().split(' ')

def solve():
	(a, b) = intlist()
	return min(a, b, (a + b) // 4)
t = input()
for tt in range(int(t)):
	print(solve())


import math
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	MAX_TEAM = (a + b) // 4
	if a >= MAX_TEAM:
		if b >= MAX_TEAM:
			print(MAX_TEAM)
		else:
			print(b)
	else:
		print(a)


def team():
	(a, b) = map(int, input().split())
	min_val = min(a, b)
	temp = (a + b) // 4
	return min(min_val, temp)
testCase = int(input())
for _ in range(testCase):
	print(team())


for _ in range(int(input())):
	(p, m) = input().split()
	p = int(p)
	m = int(m)
	if p <= 3 * m and m <= 3 * p:
		print((p + m) // 4)
		continue
	else:
		print(min(p, m))


t = int(input())
for _ in range(t):
	line = input()
	(a, b) = [int(q) for q in line.split()]
	print(min((a + b) // 4, a, b))


def team(a, b):
	if a > b:
		(a, b) = (b, a)
	if a == 0:
		return 0
	if 3 * a <= b:
		return a
	return (a + b) // 4
total = int(input())
for i in range(total):
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	print(team(a, b))


for i in range(int(input())):
	(x, y) = map(int, input().split())
	z = (x + y) // 4
	if min(x, y) >= z:
		print(z)
	else:
		print(min(x, y))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = a if a < b else b
	d = (a + b) // 4
	s = c if c < d else d
	print(s)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		big = a
		sma = b
	else:
		big = b
		sma = a
	if big > sma * 3:
		big = sma * 3
	ans = int((big + sma - (big + sma) % 4) / 4)
	print(ans)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b * 3 and b <= a * 3:
		print((a + b) // 4)
	else:
		print(min(a, b))


for i in range(int(input())):
	a = input().split()
	l = []
	for z in range(2):
		l.append(int(a[0 + z]))
	o = l[0] + l[1]
	op = o // 4
	if o < 4:
		print(0)
	elif op <= l[0] and op <= l[1]:
		print(op)
	elif op >= l[0] and op <= l[1]:
		print(l[0])
	elif op <= l[0] and op >= l[1]:
		print(l[1])


t = int(input())
ODD = {'1', '3', '5', '7', '9'}
for _ in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b >= 3 * a:
		print(a)
	else:
		print((a + b) // 4)


for i in range(int(input().strip())):
	(a, b) = map(int, input().strip().split())
	if a == b:
		print((a + b) // 4)
	elif a >= 3 * b:
		print(b)
	elif b >= 3 * a:
		print(a)
	else:
		print((a + b) // 4)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m = min(a, b)
	x = max(a, b)
	a = x - m
	if a // 2 >= m:
		print(m)
	else:
		m = m - a // 2
		print(m // 2 + a // 2)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	c = (a + b) // 4
	print(min(a, b, c))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = min((n + m) // 4, min(n, m))
	print(a)