Vishesh has gone to watch the new Spider-Man movie, but he is having troubles choosing which Popcorn-and-Coke combo to buy.

There are three combos A, B, and C available at the counter. You are given the time (in minute) for which each Popcorn bucket and Coke cup lasts. Given that Vishesh's satisfaction from a combo is defined as the total lasting time (in minute) of the Popcorn bucket and the Coke cup, find the maximum satisfaction he can get by buying a single combo.

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

- The first line of each input contains T - the number of test cases. The test cases then follow.
- The first line of each test case contains two space-separated integers A_{1} and A_{2}, meaning that for combo A, the Popcorn bucket lasts A_{1} minutes and the Coke cup lasts A_{2} minutes.
- The second line of each test case contains two space-separated integers B_{1} and B_{2}, meaning that for combo B, the Popcorn bucket lasts B_{1} minutes and the Coke cup lasts B_{2} minutes.
- The third line of each test case contains two space-separated integers C_{1} and C_{2}, meaning that for combo C, the Popcorn bucket lasts C_{1} minutes and the Coke cup lasts C_{2} minutes.

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

For each test case, output on a single line the maximum satisfaction Vishesh can get.

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

$1 ≤ T ≤ 1000$
$1 ≤ A_{1}, A_{2}, B_{1}, B_{2}, C_{1}, C_{2} ≤ 10^{9}$

----- Sample Input 1 ------ 
3
3 6
5 10
8 7
99 1
55 55
33 51
54 146
5436 627
1527 5421

----- Sample Output 1 ------ 
15
110
6948

----- explanation 1 ------ 
- Test case $1$:
- For combo $A$, the Popcorn bucket lasts $3$ minutes, and the Coke cup lasts $6$ minutes, so Vishesh gets a satisfaction of $3 + 6 = 9$ if he buys this combo.
- For combo $B$, the Popcorn bucket lasts $5$ minutes, and the Coke cup lasts $10$ minutes, so Vishesh gets a satisfaction of $5 + 10 = 15$ if he buys this combo.
- For combo $C$, the Popcorn bucket lasts $8$ minutes, and the Coke cup lasts $7$ minutes, so Vishesh gets a satisfaction of $8 + 7 = 15$ if he buys this combo.

Therefore Vishesh's maximum satisfaction is $15$.

Source: codechef | Difficulty: EASY
Tags: Mathematics


Solutions:
t = int(input())
for i in range(t):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	print(max(a1 + a2, b1 + b2, c1 + c2))


t = int(input())
for _ in range(t):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	a = a1 + a2
	b = b1 + b2
	c = c1 + c2
	print(max(a, b, c))


n = int(input())
for i in range(n):
	(a1, a2) = list(map(int, input().split()))
	(b1, b2) = list(map(int, input().split()))
	(c1, c2) = list(map(int, input().split()))
	a = a1 + a2
	b = b1 + b2
	c = c1 + c2
	print(max(a, b, c))


for _ in range(int(input())):
	combos = []
	for v in range(3):
		(a, b) = map(int, input().split())
		combos.append(a)
		combos.append(b)
	l = int(combos[0]) + int(combos[1])
	m = int(combos[2]) + int(combos[3])
	n = int(combos[4]) + int(combos[5])
	sum_lmn = [l, m, n]
	max_satsisfication = max(sum_lmn)
	print(max_satsisfication)


t = int(input())
for i in range(t):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	m1 = a1 + a2
	m2 = b1 + b2
	m3 = c1 + c2
	if m1 >= m2 and m1 >= m3:
		print(m1)
	elif m2 >= m1 and m2 >= m3:
		print(m2)
	else:
		print(m3)


test = int(input())
for _ in range(test):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	print(max([sum(a), sum(b), sum(c)]))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(p, q) = map(int, input().split())
	(x, y) = map(int, input().split())
	print(max(a + b, p + q, x + y))


t = int(input())
for i in range(t):
	maxSat = 0
	(a1, a2) = map(int, input().split())
	aSum = a1 + a2
	(b1, b2) = map(int, input().split())
	bSum = b1 + b2
	(c1, c2) = map(int, input().split())
	cSum = c1 + c2
	if aSum > bSum:
		if aSum > cSum:
			maxSat = aSum
		else:
			maxSat = cSum
	elif bSum > cSum:
		maxSat = bSum
	else:
		maxSat = cSum
	print(maxSat)


t = int(input())
for i in range(t):
	a = [int(a) for a in input().split()]
	b = [int(b) for b in input().split()]
	c = [int(c) for c in input().split()]
	print(max(sum(a), sum(b), sum(c)))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	print(max(a + b, c + d, e + f))


t = int(input())
for i in range(t):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	print(max(A1 + A2, B1 + B2, C1 + C2))


for t in range(int(input())):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	x = a1 + a2
	y = b1 + b2
	z = c1 + c2
	print(max(x, y, z))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	x = a + b
	y = c + d
	z = e + f
	print(max(x, y, z))


t = int(input(''))
for i in range(t):
	(x, y) = map(int, input().split())
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	if x + y > a + b:
		if x + y > c + d:
			print(x + y)
		else:
			print(c + d)
	elif a + b > c + d:
		print(a + b)
	else:
		print(c + d)


for _ in range(int(input())):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	A = A1 + A2
	B = B1 + B2
	C = C2 + C1
	D = max(A, B, C)
	print(D)


for i in range(int(input())):
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	L3 = list(map(int, input().split()))
	print(max(sum(L1), sum(L2), sum(L3)))


T = int(input())
for _ in range(T):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	print(max(A1 + A2, B1 + B2, C1 + C2))


tc = int(input())
for _ in range(tc):
	l = []
	for i in range(0, 3):
		(a, b) = map(int, input().split())
		res = a + b
		l.append(res)
	l.sort()
	print(l[2])


for i in range(int(input())):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	a = a1 + a2
	b = b1 + b2
	c = c1 + c2
	if a > b and a > c:
		print(a)
	elif b > a and b > c:
		print(b)
	else:
		print(c)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(a1, b1) = map(int, input().split())
	(a2, b2) = map(int, input().split())
	c = a + b
	d = a1 + b1
	e = a2 + b2
	print(max(c, d, e))


for _ in range(int(input())):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	print(max(a1 + a2, b1 + b2, c1 + c2))


for _ in range(int(input())):
	(a, a1) = map(int, input().split())
	(b, b1) = map(int, input().split())
	(c, c1) = map(int, input().split())
	print(max(a + a1, b + b1, c + c1))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	(a, b) = map(int, input().split())
	(s, t) = map(int, input().split())
	print(max(n + m, a + b, s + t))


for i in range(int(input())):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	top = A1 + A2
	if B1 + B2 > top:
		top = B1 + B2
	if C1 + C2 > top:
		top = C1 + C2
	print(top)


for _ in range(int(input())):
	A = [int(i) for i in input().split(' ')]
	B = [int(i) for i in input().split(' ')]
	C = [int(i) for i in input().split(' ')]
	print(max([sum(A), sum(B), sum(C)]))


Test = int(input())
for Cases in range(Test):
	ComboA = list(map(int, input().split()))
	ComboB = list(map(int, input().split()))
	ComboC = list(map(int, input().split()))
	SumA = sum(ComboA)
	SumB = sum(ComboB)
	SumC = sum(ComboC)
	Result = max(SumA, SumB, SumC)
	print(Result)


test_cases = int(input())
for i in range(test_cases):
	max = 0
	for j in range(3):
		(a, b) = map(int, input().split())
		if a + b >= max:
			max = a + b
	print(max)


for a in range(int(input())):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	x = max(a1 + a2, b1 + b2, c1 + c2)
	print(x)


import math
for m in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(g, h) = map(int, input().split())
	s = a + b
	t = c + d
	u = g + h
	k = max(s, t)
	print(max(u, k))


n = int(input())
for i in range(n):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = list(map(int, input().split()))
	x = l1[0] + l1[1]
	y = l2[0] + l2[1]
	z = l3[0] + l3[1]
	print(max(x, y, z))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	o = a + b
	p = c + d
	q = e + f
	print(max(o, p, q))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	if a + b >= c + d and a + b >= e + f:
		print(a + b)
	elif c + d >= a + b and c + d >= e + f:
		print(c + d)
	else:
		print(e + f)


t = int(input())
for i in range(t):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	c = a1 + a2
	d = b1 + b2
	e = c1 + c2
	if c > d and c > e:
		print(c)
	elif d > e:
		print(d)
	else:
		print(e)


t = int(input())
for t in range(t):
	(a1, b1) = input().split()
	(a2, b2) = input().split()
	(a3, b3) = input().split()
	s1 = int(a1) + int(b1)
	s2 = int(a2) + int(b2)
	s3 = int(a3) + int(b3)
	print(max(s1, s2, s3))


t = int(input())
for _ in range(t):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	combo1 = A1 + A2
	combo2 = B1 + B2
	combo3 = C1 + C2
	if combo1 > combo2 and combo1 > combo3:
		print(combo1)
	elif combo2 > combo1 and combo2 > combo3:
		print(combo2)
	else:
		print(combo3)


T = int(input())
for i in range(0, T):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	print(max(A1 + A2, max(B1 + B2, C1 + C2)))


t = int(input())
for i in range(t):
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	print(max(x1 + y1, x2 + y2, x3 + y3))


for I in range(0, int(input())):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	a = a1 + a2
	b = b1 + b2
	c = c1 + c2
	print(max(a, b, c))


n = int(input())
for i in range(n):
	l = []
	for a in range(3):
		s = input()
		l.append(s)
	l1 = l[0].split()
	l2 = l[1].split()
	l3 = l[2].split()
	s1 = int(l1[0]) + int(l1[1])
	s2 = int(l2[0]) + int(l2[1])
	s3 = int(l3[0]) + int(l3[1])
	sum = [s1, s2, s3]
	print(max(sum))


for _ in range(int(input())):
	max = 0
	for i in range(3):
		(a, b) = map(int, input().split())
		if a + b > max:
			max = a + b
	print(max)


def com():
	if a + b > c + d and a + b > e + f:
		return a + b
	elif c + d > e + f:
		return c + d
	else:
		return e + f
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	print(com())


for i in range(int(input())):
	(a1, a2) = list(map(int, input().split()))
	(b1, b2) = list(map(int, input().split()))
	(c1, c2) = list(map(int, input().split()))
	max = a1 + a2
	if b1 + b2 > max:
		max = b1 + b2
	if c1 + c2 > max:
		max = c1 + c2
	print(max)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	l1 = a + b
	l2 = c + d
	l3 = e + f
	if l1 > l2 and l1 > l3:
		print(l1)
	elif l2 > l1 and l2 > l3:
		print(l2)
	else:
		print(l3)


for i in range(int(input())):
	(p1, c1) = map(int, input().split())
	(p2, c2) = map(int, input().split())
	(p3, c3) = map(int, input().split())
	print(max(p1 + c1, p2 + c2, p3 + c3))


T = int(input())
for i in range(T):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	D = A1 + A2
	E = B1 + B2
	F = C1 + C2
	if D > E and D > F:
		print(D)
	elif F > D and F >= E:
		print(F)
	elif E > D and E >= F:
		print(E)


def main():
	t = int(input())
	for i in range(0, t):
		(a1, a2) = input().split()
		a1 = int(a1)
		a2 = int(a2)
		(b1, b2) = input().split()
		b1 = int(b1)
		b2 = int(b2)
		(c1, c2) = input().split()
		c1 = int(c1)
		c2 = int(c2)
		combo_a = a1 + a2
		combo_b = b1 + b2
		combo_c = c1 + c2
		if (combo_a >= combo_b) & (combo_a >= combo_c):
			print(combo_a)
		elif (combo_b >= combo_a) & (combo_b >= combo_c):
			print(combo_b)
		else:
			print(combo_c)
main()


t = int(input())
for i in range(t):
	(a1, b1) = map(int, input().split())
	(a2, b2) = map(int, input().split())
	(a3, b3) = map(int, input().split())
	c = a1 + b1
	d = a2 + b2
	e = a3 + b3
	f = max(c, d, e)
	print(f)


T = int(input())
for i in range(T):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	sum1 = a + b
	sum2 = c + d
	sum3 = e + f
	z = max(sum1, sum2, sum3)
	print(z)


t = int(input())
for i in range(t):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	k = a1 + a2
	l = b1 + b2
	m = c1 + c2
	if k > l and k > m:
		print(k)
	elif l >= k and l >= m:
		print(l)
	elif m > k and m > l:
		print(m)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(d, e) = map(int, input().split())
	(f, g) = map(int, input().split())
	print(max(a + b, e + d, f + g))


for i in range(int(input())):
	l = []
	for i in range(0, 3):
		(a, b) = map(int, input().split())
		l.append(a + b)
	print(max(l))


for test in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if sum(a) >= sum(b) and sum(a) >= sum(c):
		print(sum(a))
	elif sum(b) >= sum(a) and sum(b) >= sum(c):
		print(sum(b))
	else:
		print(sum(c))


T = int(input())
for t in range(T):
	(p, c) = [int(x) for x in input().split()]
	(p1, c1) = [int(x) for x in input().split()]
	(p2, c2) = [int(x) for x in input().split()]
	S1 = p + c
	S2 = p1 + c1
	S3 = p2 + c2
	S = [S1, S2, S3]
	print(max(S))


T = int(input())
for i in range(T):
	(a, a1) = map(int, input().split())
	(b, b1) = map(int, input().split())
	(c, c1) = map(int, input().split())
	A = a + a1
	B = b + b1
	C = c + c1
	ans = max(A, B, C)
	print(ans)


for i in range(int(input())):
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	d = a1 + a2
	e = b1 + b2
	f = c1 + c2
	print(max(d, e, f))


T = int(input())
for i in range(T):
	(A1, A2) = map(int, input().split())
	(B1, B2) = map(int, input().split())
	(C1, C2) = map(int, input().split())
	a = A1 + A2
	b = B1 + B2
	c = C1 + C2
	if a > b and a > c:
		print(a)
	elif b > a and b > c:
		print(b)
	else:
		print(c)