Given three distinct integers $a$, $b$, and $c$, find the medium number between all of them.

The medium number is the number that is neither the minimum nor the maximum of the given three numbers.

For example, the median of $5,2,6$ is $5$, since the minimum is $2$ and the maximum is $6$.


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 6840$) — the number of test cases.

The description of each test case consists of three distinct integers $a$, $b$, $c$ ($1 \leq a, b, c \leq 20$).


-----Output-----

For each test case, output a single integer — the medium number of the three numbers.


-----Examples-----

Input
9
5 2 6
14 3 4
20 2 1
1 2 3
11 19 12
10 8 20
6 20 3
4 1 3
19 8 4
Output
5
4
2
2
12
10
6
3
8


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Sorting

Implementation


Solutions:
t = int(input())
ans = [0] * t
for i in range(t):
	a = sorted(list(map(int, input().split())))
	ans[i] = a[1]
print('\n'.join(map(str, ans)))


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	print(sorted(list(map(int, stdin.readline().split())))[1])


l = []
for _ in range(int(input())):
	l.append(list(map(int, input().split())))

def calc(i):
	max_ = max(i)
	min_ = min(i)
	return sum(i) - min_ - max_
for i in l:
	print(calc(i))


import sys
from sys import stdin
import heapq
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
input = sys.stdin.readline
t = int(input())
res = []
for _ in range(t):
	lis = list(map(int, input().split()))
	lis.sort()
	res.append(lis[1])
print(*res, sep='\n')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	nums = list(map(int, input().split()))
	nums.sort()
	print(nums[1])


def bin(a, val):
	l = -1
	r = len(a)
	while r - l > 1:
		m = (r + l) // 2
		if a[m] >= val:
			r = m
		else:
			l = m
	return r
n = int(input())
h = []
for i in range(n):
	a = list(map(int, input().split()))
	a1 = a[0]
	a2 = a[1]
	a3 = a[2]
	if a1 > a2 and a2 > a3:
		h.append(a2)
	if a3 > a2 and a2 > a1:
		h.append(a2)
	if a1 > a2 and a3 > a1:
		h.append(a1)
	if a1 > a3 and a2 > a1:
		h.append(a1)
	if a3 > a2 and a1 > a3:
		h.append(a3)
	if a3 > a1 and a2 > a3:
		h.append(a3)
for t in h:
	print(t)


def Mid(a, b, c):
	if c < a and c < b:
		return b if b < a else a
	r = a if a > b else b
	return r if r < c else c
a = []
for _ in range(0, int(input())):
	(x, y, z) = map(int, input().split())
	re = Mid(x, y, z)
	a.append(re)
for i in a:
	print(i)


n = int(input())
result = []
for i in range(n):
	a = input()
	b = []
	for i in a.split():
		b += [int(i)]
	b.sort()
	result += [b[len(b) // 2]]
for i in result:
	print(i)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	a = sorted(list(map(int, input().split())))
	print(a[1])


n = int(input())
result = []
for _ in range(n):
	l = list(map(int, input().split()))
	l.sort()
	result.append(l[1])
for i in result:
	print(i)


def main():
	n = int(input())
	d = []
	for i in range(n):
		a = list(map(int, input().split()))
		a.sort()
		d.append(a[1])
	for i in range(n):
		print(d[i])
main()


a = int(input())
ans = []
for i in range(a):
	x = list(map(int, input().split()))
	x.remove(max(x))
	x.remove(min(x))
	ans.append(x)
for i in ans:
	print(*i)


n = int(input())
res = []
for i in range(n):
	num_list = list(map(int, input().split()))
	num_list.remove(max(num_list))
	num_list.remove(min(num_list))
	res.append(num_list[0])
print(*res, sep='\n')


x = int(input())
z = 0
list = []
list0 = []
while x > z:
	(a, b, c) = map(int, input().split())
	if a in range(b, c + 1) or a in range(c, b + 1):
		list.append(a)
	elif b in range(a, c + 1) or b in range(c, a + 1):
		list.append(b)
	elif c in range(a, b + 1) or c in range(b, c + 1):
		list.append(c)
	z += 1
for i in list:
	print(i)


n = int(input())
ans = 0
num = []
for i in range(n):
	num.append(list(map(int, input().split())))
for i in range(n):
	for j in range(len(num[i])):
		if num[i][j] != max(num[i]) and num[i][j] != min(num[i]):
			print(num[i][j])
			break


num = int(input())
s = []
i = 0
while i < num:
	s.append(input())
	i = i + 1
for set in s:
	n = set.split(' ')
	i = 0
	while i < 3:
		n[i] = int(n[i])
		i = i + 1
	n.sort()
	print(n[1])


ans = []
for _ in range(int(input())):
	a = list(map(int, input().split()))
	ans.append(sorted(a)[1])
print(*ans, sep='\n')


t = int(input())
C = []
for i in range(t):
	A = []
	B = []
	(a, b, c) = map(int, input().split())
	A += [a]
	A += [b]
	A += [c]
	if a != max(A) and a != min(A):
		B += [a]
	if b != max(A) and b != min(A):
		B += [b]
	if c != max(A) and c != min(A):
		B += [c]
	C += [*B]
for i in C:
	print(i)


n = int(input())
a = []
for i in range(n):
	l = list(map(int, input().split()))
	l.sort()
	a.append(l[1])
for i in a:
	print(i)


for _ in range(int(input())):
	listx = list(map(int, input().split()))
	listy = sorted(listx)
	print(listy[1])


from sys import stdin
for _ in range(int(stdin.readline().strip())):
	print(sorted(map(int, stdin.readline().strip().split()))[1])


m = int(input())
x = [0] * m
for i in range(0, m):
	(a, b, c) = map(int, input().split())
	x[i] = 0
	if a < b and a < c:
		if c > b:
			x[i] = b
		elif b > c:
			x[i] = c
	elif b < a and b < c:
		if c > a:
			x[i] = a
		elif a > c:
			x[i] = c
	elif c < a and b > c:
		if b > a:
			x[i] = a
		elif a > b:
			x[i] = b
for i in range(0, m):
	print(x[i])


t = int(input())
o = []
for i in range(t):
	n = map(int, input().split())
	n = list(n)
	d = max(n)
	n.remove(d)
	f = max(n)
	o.append(f)
for i in o:
	print(i)


user_input = int(input())
list = []
for i in range(0, user_input):
	n = input()
	listi = n.split(' ')
	for j in listi:
		list.append(int(j))
for i in range(0, len(list), 3):
	list1 = list[i:i + 3]
	if list1[2] < list1[0] < list1[1]:
		print(list1[0])
	if list1[0] < list1[1] < list1[2]:
		print(list1[1])
	if list1[1] < list1[2] < list1[0]:
		print(list1[2])
	if list1[1] < list1[0] < list1[2]:
		print(list1[0])
	if list1[2] < list1[1] < list1[0]:
		print(list1[1])
	if list1[0] < list1[2] < list1[1]:
		print(list1[2])


x = eval(input())
k = []
while x > 0:
	l = []
	(a, b, c) = map(int, input().split(' '))
	l.append(a)
	l.append(c)
	l.append(b)
	l.sort()
	k.append(l[1])
	x -= 1
for i in k:
	print(i)


import itertools
import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
import os

def solve(a, b, c):
	print(sorted([a, b, c])[1])
for i in range(inp()):
	(a, b, c) = invr()
	solve(a, b, c)


noof = int(input())
prob = []
for i in range(noof):
	inn = input().split(' ')
	a = int(inn[0])
	b = int(inn[1])
	c = int(inn[2])
	if a > b:
		if c > a:
			prob.append(a)
		elif b > c:
			prob.append(b)
		else:
			prob.append(c)
	elif c > b:
		prob.append(b)
	elif a > c:
		prob.append(a)
	else:
		prob.append(c)
for i in prob:
	print(i)


num = int(input())
a = None
c = None
b = []
d = ''
x = []
for i in range(num):
	z = str(input())
	for r in z:
		if r != ' ':
			d = d + r
		else:
			b.append(int(d))
			d = ''
			continue
	b.append(int(d))
	d = ''
	if b[0] <= b[1] <= b[2]:
		a = b[1]
		x.append(a)
	elif b[1] <= b[0] <= b[2]:
		a = b[0]
		x.append(a)
	elif b[1] <= b[2] <= b[0]:
		a = b[2]
		x.append(a)
	elif b[0] <= b[2] <= b[1]:
		a = b[2]
		x.append(a)
	elif b[2] <= b[1] <= b[0]:
		a = b[1]
		x.append(a)
	elif b[2] <= b[0] <= b[1]:
		a = b[0]
		x.append(a)
	b = []
for i in x:
	print(i)


n = int(input())
m = []
for i in range(n):
	x = list(input().split())
	l = []
	for j in x:
		l.append(int(j))
	sort = sorted(l)
	m.append(sort[1])
for num in m:
	print(num)


def medium(a, b, c):
	(a, b, c) = (int(a), int(b), int(c))
	if a > b:
		if a > c:
			if b > c:
				return b
			else:
				return c
		else:
			return a
	elif b > a:
		if b > c:
			if a > c:
				return a
			else:
				return c
		else:
			return b
test_size = int(input())
final = []
for i in range(test_size):
	temp = []
	temp = input().split()
	final.append(medium(*temp))
for i in final:
	print(i)


import sys
input = sys.stdin.readline
N = int(input())
for i in range(N):
	l = [int(j) for j in input().strip().split()]
	min = 100
	max = 0
	for a in l:
		if a > max:
			max = a
		if a < min:
			min = a
	for a in l:
		if (a != min) & (a != max):
			print(a)


for s in [*open(0)][1:]:
	print(sorted(s.split(), key=int)[1])


print('\n'.join((sorted(i.split(), key=lambda x: int(x))[1] for i in [*open(0)][1:])))


import sys
input = sys.stdin.readline
nel = int(input())
for iline in range(nel):
	els = list(map(int, input().split(' ')))
	els = sorted(els)
	print(els[1])


t = int(input())
medium = str()
for i in range(t):
	x = input().split()
	if int(x[0]) > int(x[1]) and int(x[0]) < int(x[2]) or (int(x[0]) < int(x[1]) and int(x[0]) > int(x[2])):
		medium = medium + x[0] + '\n'
	elif int(x[1]) > int(x[0]) and int(x[1]) < int(x[2]) or (int(x[1]) < int(x[0]) and int(x[1]) > int(x[2])):
		medium = medium + x[1] + '\n'
	elif int(x[2]) > int(x[0]) and int(x[2]) < int(x[1]) or (int(x[2]) < int(x[0]) and int(x[2]) > int(x[1])):
		medium = medium + x[2] + '\n'
print(medium[:len(medium) - 1])


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	a = list(map(int, sys.stdin.readline().split()))
	a.sort()
	print(a[1])


n = int(input())
lista = []
for x in range(n):
	a = input().split()
	a = [int(i) for i in a]
	a.sort()
	lista.append(a[1])
for x in lista:
	print(x)


t = int(input())
r = list()
for i in range(t):
	s = list(map(int, input().split()))
	s.sort()
	r.append(s[1])
print(*r, sep='\n')


n = int(input())
all_list = []
for i in range(n):
	abc = input().split()
	abc = list(map(int, abc))
	abc.sort()
	all_list.append(abc[1])
for i in all_list:
	print(i)


n = int(input())
l = [[int(i) for i in input().split(' ')] for j in range(n)]
for i in range(n):
	print(sorted(l[i])[1])


n = int(input())
lst = []
lst2 = []
lst3 = []
for i in range(n):
	num = input().split()
	for j in range(len(num)):
		num[j] = int(num[j])
	lst.append(num)
for i in lst:
	i.sort()
	lst2.append(i[1])
for i in lst2:
	print(i)


for st in [*open(0)][1:]:
	print(sorted(st.split(), key=int)[1])


length = int(input())
str = []
for i in range(length):
	str.append(input())
for i in range(length):
	data = str[i].split()
	x = int(data[0])
	y = int(data[1])
	z = int(data[2])
	if x <= y and x >= z or (x >= y and x <= z):
		print(x)
	elif y <= x and y >= z or (y >= x and y <= z):
		print(y)
	else:
		print(z)


t = int(input())
medium = []
for i in range(t):
	list1 = list(map(int, input().split()))
	list1.remove(max(list1))
	list1.remove(min(list1))
	medium.extend(list1)
print(*medium, sep='\n')


t = int(input())
for i in range(t):
	z = [int(s) for s in input().split()]
	z = sorted(z)
	print(z[1])


t = int(input())
for it in range(t):
	a = list(map(int, input().split()))
	a = sorted(a)
	print(a[1])


t = int(input())
for test in range(t):
	a = list(map(int, input().split()))
	a.sort()
	print(a[1])


for _ in range(int(input())):
	a = list(map(int, input().split()))
	maxer = max(a)
	miner = min(a)
	for i in a:
		if i != maxer and i != miner:
			print(i)
			break


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


t = int(input())
for i in range(t):
	arrr = list(map(int, input().split()))
	arr = sorted(arrr)
	print(arr[1])


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	print(a + b + c - max(a, b, c) - min(a, b, c))


t = int(input())
for i in range(t):
	m = list(map(int, input().split()))
	m.sort()
	print(m[1])


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	print(l[1])


for i in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	print(a[1])


import sys
t = int(sys.stdin.readline())
for i in range(t):
	lst = list(map(int, input().split()))
	lst.sort()
	print(lst[1])


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a = sorted(a)
	print(a[1])


for _ in range(int(input())):
	x = list(map(int, input().split()))
	x.sort()
	print(x[1])


n = int(input())
for i in range(n):
	n = list(map(int, input().split()))
	n = sorted(n)
	print(n[1])


for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	a.sort()
	print(a[1])


t = int(input())
for _ in range(t):
	n = list(map(int, input().split()))
	n.sort()
	print(n[1])


t = int(input())
for i in range(t):
	n = list(map(int, input().split(sep=' ')))
	n.remove(max(n))
	n.remove(min(n))
	print(n[0])


n = int(input())
trigger = False
for i in range(n):
	(a, b, c) = [int(k) for k in input().split()]
	print(a + b + c - max(a, b, c) - min(a, b, c))


t = int(input())
for i in range(t):
	l = [int(k) for k in input().split()]
	l.sort()
	print(l[1])


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	l = []
	l.append(a)
	l.append(b)
	l.append(c)
	l = sorted(l)
	print(l[1])


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	li = [a, b, c]
	li.sort()
	print(li[1])


a = int(input())
for i in range(a):
	(a, b, c) = map(int, input().split())
	if a < b < c or c < b < a:
		print(b)
	elif b < a < c or c < a < b:
		print(a)
	else:
		print(c)


def solve():
	a = list(map(int, input().split()))
	a.sort()
	print(a[1])
for t in range(0, int(input())):
	solve()


t = int(input())
for tc in range(t):
	l = list(map(int, input().split()))
	l.sort()
	print(l[1])


def srednee(arr):
	maxa = max(arr)
	mina = min(arr)
	for i in range(3):
		if arr[i] != maxa and arr[i] != mina:
			return arr[i]
			break
kn = int(input())
for i in range(kn):
	lis = list(map(int, input().split()))
	print(srednee(lis))


t = int(input())
for i in range(t):
	y = input().split()
	y = [int(a) for a in y]
	(a, b, c) = (y[0], y[1], y[2])
	new = [max(y), min(y)]
	for i in y:
		if i not in new:
			print(i)


t = int(input())
while t > 0:
	t -= 1
	l = [int(i) for i in input().split(' ')]
	l.sort()
	print(l[1])


T = int(input())
for i in range(T):
	(a, b, c) = map(int, input().split())
	k = []
	k.append(a)
	k.append(b)
	k.append(c)
	k.sort()
	print(k[1])


Q = int(input())
for i in range(Q):
	A = list(map(int, input().split()))
	A.sort()
	print(A[1])


for i in range(int(input())):
	l = [int(x) for x in input().split()]
	h = sum(l) - min(l) - max(l)
	print(h)


q = int(input())
for _ in range(q):
	nums = list(map(int, input().split()))
	nums.sort()
	print(nums[1])


t = int(input())
while t:
	l = list(map(int, input().split()))
	l.sort()
	print(l[1])
	t -= 1


tst = int(input())
for _ in range(tst):
	lst = list(map(int, input().split()))
	lst.sort()
	print(lst[1])


t = int(input())
while t != 0:
	(a, b, c) = map(int, input().split())
	l = []
	l.append(a)
	l.append(b)
	l.append(c)
	l.sort()
	print(l[1])
	t -= 1


t = int(input())
while t:
	(a, b, c) = map(int, input().split())
	if b > a and b < c or (b > c and b < a):
		print(b)
	elif c > a and c < b or (c > b and c < a):
		print(c)
	else:
		print(a)
	t = t - 1


t = int(input())
for _ in range(t):
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	print(arr[1])


t = int(input())
out = []
while t > 0:
	a = list(map(int, input().split()))
	a.remove(max(a))
	a.remove(min(a))
	out.append(a[0])
	t -= 1
for i in out:
	print(i)


for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	ans = [a, b, c]
	x = max(ans)
	y = min(ans)
	ans.remove(x)
	ans.remove(y)
	print(*ans)