You are given a sequence a1, a2, ..., aN. Find the smallest possible value of ai + aj, where 1 ≤ i < j ≤ N.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. 
The first line of each description consists of a single integer N.
The second line of each description contains N space separated integers - a1, a2, ..., aN respectively.

-----Output-----
For each test case, output a single line containing a single integer - the smallest possible sum for the corresponding test case.

-----Constraints-----

- T = 105, N = 2 : 13 points.
- T = 105, 2 ≤ N ≤ 10 : 16 points.
- T = 1000, 2 ≤ N ≤ 100 : 31 points.
- T = 10, 2 ≤ N ≤ 105 : 40 points.
- 1 ≤ ai ≤ 106

-----Example-----
Input:
1
4
5 1 3 4

Output:
4

-----Explanation-----
Here we pick a2 and a3. Their sum equals to 1 + 3 = 4.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	lst = sorted(list(map(int, input().split())))
	print(lst[0] + lst[1])


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


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


T = int(input())
arr = []
for i in range(T):
	N = int(input())
	arr.append(list(map(int, input().split()[:N])))
for i in arr:
	a = min(i)
	i.remove(a)
	b = min(i)
	print(a + b)


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


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


def __starting_point():
	try:
		for _ in range(int(input())):
			element = int(input())
			l = list(map(int, input().split()))
			a = min(l)
			l.remove(a)
			b = min(l)
			print(a + b)
	except EOFError:
		print('EOFError')
__starting_point()


a = int(input(''))
for i in range(a):
	x = int(input(''))
	T = [int(x) for x in input().split()]
	k = list(T)
	k.sort()
	print(k[0] + k[1])


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a1 = min(a)
	a.remove(a1)
	a2 = min(a)
	print(a1 + a2)


try:
	for i in range(int(input())):
		val = int(input())
		arr = list(map(int, input().split()))
		arr.sort()
		print(arr[0] + arr[1])
except:
	pass


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


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


T = int(input())
for i in range(T):
	N = int(input())
	A = [int(x) for x in input().split()]
	A.sort()
	print(A[0] + A[1])


t = int(input())
while t:
	n = int(input())
	arr = input().split(' ')
	min1 = 10 ** 9
	min2 = 10 ** 9
	for i in range(n):
		if int(arr[i]) <= min1:
			min2 = min1
			min1 = int(arr[i])
			continue
		if int(arr[i]) < min2:
			min2 = int(arr[i])
	print(min1 + min2)
	t = t - 1


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


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	k = 0
	for i in range(2):
		k += min(s)
		s.remove(min(s))
	print(k)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l.reverse()
	print(l[-1] + l[-2])


try:
	for t in range(int(input())):
		n = int(input())
		a = list(map(int, input().split(' ')))
		s = min(a)
		a.remove(s)
		ss = min(a)
		print(s + ss)
except:
	pass


def smallest(lst, n):
	if n == 2:
		print(lst[0] + lst[1])
	elif 2 < n <= 10:
		mini = lst[0] + lst[1]
		for j in range(2, n):
			suM = lst[j - 1] + lst[j]
			if suM < mini:
				mini = suM
		print(mini)

def __starting_point():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = [int(i) for i in input().split()]
		smallest(arr, n)
__starting_point()


T = int(input())
for t in range(T):
	N = int(input())
	A = [int(x) for x in input().split()]
	m = A[0] + A[1]
	for i in range(N):
		for j in range(i + 1, N):
			cur = A[i] + A[j]
			if cur < m:
				m = cur
	print(m)


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


test = int(input())
while test is not 0:
	a = int(input())
	l = list(map(int, input().split()))
	l.sort()
	print(l[0] + l[1])
	test -= 1


a = []
T = int(input())
for i in range(T):
	x = int(input())
	a.append(list(map(int, input().split())))
	a[i].sort()
for j in range(T):
	print(a[j][0] + a[j][1])


t = int(input())
while t:
	o = int(input())
	data = input()
	arr = data.split(' ')
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	arr.sort()
	print(arr[0] + arr[1])
	t -= 1


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


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	print(a[0] + a[1])
	t -= 1


for t in range(int(input())):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l1.sort()
	print(l1[0] + l1[1])


n = int(input())
for i in range(n):
	n1 = int(input())
	L1 = list(map(int, input().split()))
	L1.sort()
	print(L1[0] + L1[1])


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


t = int(input())

def pair(arr):
	min1 = min(arr)
	arr.remove(min1)
	min2 = min(arr)
	print(min1 + min2)
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pair(arr)


K1 = int(input())
for j in range(K1):
	K = int(input())
	L1 = list(map(int, input().split()))
	L1.sort()
	print(L1[0] + L1[1])


EP = int(input())
for i in range(EP):
	ep = int(input())
	pc = list(map(int, input().split()))
	pc.sort()
	print(pc[0] + pc[1])


n = int(input())
for i in range(n):
	num = int(input())
	lis = list(map(int, input().split()))
	mini = min(lis)
	lis.remove(mini)
	mini2 = min(lis)
	print(mini + mini2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	s += min(a)
	a.remove(min(a))
	s += min(a)
	print(s)


d = int(input())
for i in range(d):
	w = int(input())
	r = list(map(int, input().split()))
	r.sort()
	print(r[0] + r[1])


T = int(input())
for i in range(T):
	n = int(input())
	s = list(map(int, input().split()))
	s.sort()
	print(s[0] + s[1])


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


test_cases = int(input())
for i in range(test_cases):
	n = int(input())
	string = list(map(int, input().split()))[:n]
	string.sort()
	print(string[0] + string[1])


try:
	for t in range(int(input())):
		n = int(input())
		a = list(map(int, input().split(' ')))
		small = min(a)
		a.remove(small)
		small1 = min(a)
		print(small + small1)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	l = [int(n) for n in input().split()]
	a = min(l)
	l.remove(a)
	b = min(l)
	print(a + b)


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


t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	ans = li[0] + li[1]
	print(ans)


from math import sqrt, ceil, floor, gcd, log2
import sys
from sys import stdin, stdout
from collections import Counter, defaultdict, OrderedDict, deque
from itertools import combinations, groupby
from time import time
from heapq import heappop, heappush, heapify
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	print(arr[0] + arr[1])


n = int(input())
for i in range(n):
	a = int(input())
	l = list(map(int, input().split()))
	s = min(l)
	l.remove(s)
	k = min(l)
	print(s + k)


def smallest(lst, n):
	if n == 2:
		print(lst[0] + lst[1])
	else:
		mini = lst[0] + lst[1]
		for j in range(1, n):
			for k in range(j + 1, n):
				s = lst[j] + lst[k]
				if s < mini:
					mini = s
		print(mini)

def __starting_point():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = [int(i) for i in input().split()]
		smallest(arr, n)
__starting_point()


def smallest(lst, n):
	if n == 2:
		print(lst[0] + lst[1])
	else:
		reslst = []
		mini = lst[0] + lst[1]
		for j in lst:
			for k in lst:
				if lst.index(j) == lst.index(k):
					continue
				s = j + k
				reslst.append(s)
		print(min(reslst))

def __starting_point():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = [int(i) for i in input().split()]
		smallest(arr, n)
__starting_point()