Two friends like to pool their money and go to the ice cream parlor.  They always choose two distinct flavors and they spend all of their money.

Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they have.  

Example. 
$m=6$
$cost=[1,3,4,5,6]$

The two flavors that cost $\mbox{I}$ and $5$ meet the criteria.  Using $\mbox{1}$-based indexing, they are at indices $\mbox{1}$ and $\begin{array}{c}4\end{array}$.  

Function Description

Complete the icecreamParlor function in the editor below.    

icecreamParlor has the following parameter(s):  

int m: the amount of money they have to spend  
int cost[n]: the cost of each flavor of ice cream  

Returns   

int[2]:  the indices of the prices of the two flavors they buy, sorted ascending 

Input Format

The first line contains an integer, $\boldsymbol{\boldsymbol{t}}$, the number of trips to the ice cream parlor.   The next $\boldsymbol{\boldsymbol{t}}$ sets of lines each describe a visit.  

Each trip is described as follows:

The integer $m$, the amount of money they have pooled. 
The integer $n$, the number of flavors offered at the time. 
$n$ space-separated integers denoting the cost of each flavor: $cost[cost[1],cost[2],...,cost[n]]$.  

Note:  The index within the cost array represents the flavor of the ice cream purchased.  

Constraints

$1\leq t\leq50$  
$2\leq m\leq10^4$   
$2\leq n\leq10^4$   
$1\leq c o s t[i]\leq10^4$, ∀ $i\in[1,n]$   
There will always be a unique solution.

Sample Input
STDIN       Function
-----       --------
2           t = 2
4           k = 4
5           cost[] size n = 5
1 4 5 3 2   cost = [1, 4, 5, 3, 2]
4           k = 4
4           cost[] size n = 4
2 2 4 3     cost=[2, 2,4, 3]

Sample Output
1 4
1 2

Explanation

Sunny and Johnny make the following two trips to the parlor:

The first time, they pool together $m=4$ dollars. Of the five flavors available that day, flavors $\mbox{1}$ and $\begin{array}{c}4\end{array}$ have a total cost of $1+3=4$.  
The second time, they pool together $m=4$ dollars. Of the four flavors available that day, flavors $\mbox{1}$ and $2$ have a total cost of $2+2=4$.

Difficulty: EASY
Tags: Complete search
Skill types: Complete search

Starter code:

Solutions:
def main():
	for _ in range(int(input())):
		dollars = int(input())
		numFlavors = int(input())
		flavors = [int(i) for i in input().split()]
		(index1, index2) = (-1, -1)
		for i in range(numFlavors):
			for j in range(numFlavors):
				if i != j and flavors[i] + flavors[j] == dollars:
					index1 = i + 1
					index2 = j + 1
					break
			if index1 != -1 and index2 != -1:
				break
		print(str(index1) + ' ' + str(index2))
main()


def read_file():
	data = []
	line = input()
	N = int(line.strip('\n'))
	for i in range(N):
		line = input()
		C = int(line.strip('\n'))
		line = input()
		line = input()
		L = line.strip('\n').split()
		L = list(map(int, L))
		data.append([C, L])
	return data

def write_file(answers):
	for ans in answers:
		print(str(ans[0]) + ' ' + str(ans[1]))

def find_two(C, L):
	for i in range(len(L)):
		if L[i] >= C:
			continue
		for j in range(i + 1, len(L)):
			if L[i] + L[j] == C:
				return [i + 1, j + 1]
	return [0, 0]

def main():
	data_set = read_file()
	answers = []
	for data in data_set:
		answers.append(find_two(data[0], data[1]))
	write_file(answers)
main()


t = int(input())
while t:
	t -= 1
	c = int(input())
	l = int(input())
	prices = [int(x) for x in input().split()]
	found = False
	for i in range(l):
		for j in range(i + 1, l):
			if prices[i] + prices[j] == c:
				found = True
				break
		if found:
			break
	print('{0} {1}'.format(i + 1, j + 1))


import sys
data = sys.stdin.readlines()
n = int(data[0][:-1])
for offset in range(n):
	c = int(data[offset * 3 + 1][:-1])
	l = int(data[offset * 3 + 2][:-1])
	flavors = data[offset * 3 + 3][:-1].split(' ')
	cost_left = {}
	for i in range(len(flavors)):
		cost = int(flavors[i])
		if cost in cost_left:
			print('{0} {1}'.format(cost_left[cost], i + 1))
			break
		else:
			cost_left[c - cost] = i + 1


import sys

def canSumTo(C, costs):
	truth = False
	for (index, element) in enumerate(costs[:-1]):
		newarray = costs[index:]
		for (newindex, newelement) in enumerate(newarray[1:]):
			if newelement + element == C:
				print(index + 1, newindex + index + 2)
				return

def parse(inp):
	inp = inp.split('\n')
	testcases = int(inp[0])
	inp = inp[1:]
	for i in range(testcases):
		C = int(inp[i * 3])
		costs = list(map(int, inp[i * 3 + 2].split()))
		canSumTo(C, costs)
	return 'swag!'
input_string = ''
for line in sys.stdin:
	input_string += line
parse(input_string)


T = int(input())
for test_case in range(T):
	cash = int(input())
	no_flavs = int(input())
	flav_costs = input()
	F = flav_costs.split()
	done = False
	Flav = {}
	for i in range(len(F)):
		value = int(F[i])
		if value < cash:
			if not value in Flav:
				Flav[value] = [i + 1]
			else:
				Flav[value].append(i + 1)
	for each in Flav:
		rem = cash - each
		try:
			b = Flav[rem][0]
			a = Flav[each][0]
			if a == b:
				if len(Flav[each]) == 2:
					print(Flav[each][0], Flav[each][1])
					break
			else:
				print(min(a, b), max(a, b))
				break
		except:
			pass


from sys import stdin

def gen(L):
	for i in range(L - 1):
		for j in range(i + 1, L):
			yield (i, j)
T = int(stdin.readline())
for t in range(T):
	C = int(stdin.readline())
	L = int(stdin.readline())
	I = list(map(int, stdin.readline().split(' ')))
	for (i, j) in gen(L):
		if I[i] + I[j] == C:
			print(i + 1, j + 1)
			break


T = int(input())
for i in range(T):
	C = int(input())
	L = int(input())
	flavor_list = input().split()
	flavor_dict = dict()
	for j in range(len(flavor_list)):
		cost = int(flavor_list[j])
		if cost in flavor_dict:
			flavor_dict[cost].append(j)
		else:
			flavor_dict[cost] = [j]
	for j in range(len(flavor_list)):
		cost = int(flavor_list[j])
		if C - cost in flavor_dict:
			pair = j
			for k in flavor_dict[C - cost]:
				if k != j:
					pair = k
			if pair != j:
				print('{} {}'.format(j + 1, pair + 1))
				break


import sys
import re

def findCombos(c, l, flavors):
	for i in range(l):
		for j in range(l):
			if flavors[i] + flavors[j] == c and (not i == j):
				return (i, j)
numtests = int(sys.stdin.readline())
numlines = 0
while numtests:
	c = int(sys.stdin.readline())
	l = int(sys.stdin.readline())
	line = sys.stdin.readline()
	flavors = [int(x) for x in re.findall('\\d*', line) if x != '']
	ans = findCombos(c, l, flavors)
	print(ans[0] + 1, ans[1] + 1)
	numtests -= 1


from sys import stdin
from ctypes import c_uint16
TYPE_CACHE = c_uint16 * 10000

def read_stdin():
	T = int(stdin.readline().strip())
	while T > 0:
		T -= 1
		C = int(stdin.readline().strip())
		L = int(stdin.readline().strip())
		prices = tuple(map(int, stdin.readline().strip().split()))
		cache = TYPE_CACHE()
		print(' '.join(solve(C, L, prices, cache)))

def solve(C, L, prices, cache):
	for i in range(L):
		price = prices[i]
		price_comlement = C - price
		if price_comlement < 1:
			continue
		if cache[price_comlement]:
			return (str(cache[price_comlement]), str(i + 1))
		cache[price] = i + 1
	return (0, 0)
read_stdin()


def findFlavors(cost, flavorsList):
	amount = 0
	for i in range(len(flavorsList)):
		j = i + 1
		if j >= len(flavorsList):
			j = 0
		while j != i:
			amount = flavorsList[i] + flavorsList[j]
			if amount == cost:
				return (i + 1, j + 1)
			else:
				j += 1
				if j >= len(flavorsList):
					j = 0

def main():
	numTestCases = int(input())
	out = []
	for i in range(numTestCases):
		cost = int(input())
		flavors = input()
		flavorsList = input().split()
		flavorsList = [int(i) for i in flavorsList]
		(f1, f2) = findFlavors(cost, flavorsList)
		out.append([f1, f2])
	for item in out:
		print(item[0], item[1])
main()


from itertools import combinations
T = int(input())
for t in range(T):
	C = int(input())
	N = int(input())
	V = [int(x) for x in input().split()]
	for p in combinations(range(N), 2):
		if sum([V[x] for x in p]) == C:
			print(str([x + 1 for x in p])[1:-1].replace(',', ''))
			break


import sys
numTests = int(sys.stdin.readline())
for i in range(numTests):
	dollars = int(sys.stdin.readline())
	numFlavors = int(sys.stdin.readline())
	costs = {}
	blacklist = set()
	values = sys.stdin.readline().split()
	for j in range(len(values)):
		if int(values[j]) not in costs:
			costs[int(values[j])] = [j + 1]
		else:
			costs[int(values[j])] += [j + 1]
	for key in costs:
		if key not in blacklist and dollars - key not in blacklist:
			if dollars - key in costs:
				p = costs[key][0]
				q = costs[dollars - key][-1]
				if p <= q:
					print(p, q)
				else:
					print(q, p)
				break
			else:
				blacklist.add(key)
				blacklist.add(dollars - key)


import sys
L = [1, 4, 5, 3, 2]
C = 4

def find(L, C):
	i = 0
	j = 0
	while i < len(L):
		j = i + 1
		while j < len(L):
			if L[i] + L[j] == C:
				return (i + 1, j + 1)
			j += 1
		i += 1

def runcommand():
	num_cases = int(sys.stdin.readline())
	for _ in range(num_cases):
		cost = int(sys.stdin.readline())
		_numFlavours = int(sys.stdin.readline())
		flavours = list(map(int, sys.stdin.readline().split()))
		(x, y) = find(flavours, cost)
		print(x, y)
runcommand()


def solve():
	m = int(input())
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] + a[j] == m:
				print(str(i + 1) + ' ' + str(j + 1))
t = int(input())
for i in range(t):
	solve()


def printer(first, second):
	if first < second:
		print(first, second)
	else:
		print(second, first)
n = int(input())
for i in range(n):
	cost = int(input())
	l = int(input())
	listl = input().strip().split()
	listl = [int(entry) for entry in listl]
	listdict = dict()
	position = 1
	for entry in listl:
		if entry in listdict:
			listdict[entry].append(position)
		else:
			listdict[entry] = [position]
		position += 1
	for entry in listl:
		other = cost - entry
		if other in listdict:
			if len(listdict[other]) == 2:
				first = listdict[other][0]
				second = listdict[other][1]
				printer(first, second)
				break
			else:
				first = listdict[entry][0]
				second = listdict[other][0]
				if first != second:
					printer(first, second)
					break


t = int(input())
for j in range(t):
	c = int(input())
	l = int(input())
	loc = input().split()
	loc = [int(loc[i]) for i in range(l)]
	sl = list(loc)
	sl.sort()
	index2 = -1
	i = 0
	while index2 == -1:
		a = c - sl[i]
		try:
			index2 = loc.index(a)
			break
		except Exception:
			index2 = -1
		i += 1
	loc[index2] = 0
	i = loc.index(c - a)
	print(min(i + 1, index2 + 1), max(i + 1, index2 + 1))


T = int(input())
for i in range(T):
	C = int(input())
	L = int(input())
	flavor_prices = [(i + 1, int(x)) for (i, x) in enumerate(input().split())]
	half = []
	prices = {}
	for (i, p) in flavor_prices:
		if p == C / 2:
			half.append(i)
		else:
			prices[p] = i
	if len(half) == 2:
		f = tuple(sorted(half))
	else:
		for price in prices:
			if C - price in prices:
				f = (prices[price], prices[C - price])
				f = tuple(sorted(f))
				break
	print('%d %d' % f)


t = int(input())
for k in range(0, t):
	c = int(input())
	fl = int(input())
	f = input().strip()
	f = list(map(int, f.split(' ')))
	k = 0
	akh = False
	for i in f:
		rs = c - int(i)
		if rs > 0:
			for j in range(k + 1, len(f)):
				if f[j] == rs:
					print(k + 1, j + 1)
					akh = True
					break
		if akh:
			break
		k = k + 1


def func(n, ar):
	(s, e) = (0, len(ar) - 1)
	while 1:
		if ar[s][0] + ar[e][0] == n:
			return sorted([ar[s][1], ar[e][1]])
		elif ar[s][0] + ar[e][0] > n:
			e -= 1
		else:
			s += 1
t = int(input())
for a in range(t):
	n = int(input())
	m = int(input())
	in_ar = input().split()
	ar = [(int(in_ar[i]), i + 1) for i in range(m)]
	ar.sort()
	print(*func(n, ar))


t = int(input())
for i in range(0, t):
	c = int(input())
	l = int(input())
	f = [int(g) for g in input().split()]
	x = 0
	y = 0
	found = False
	for j in range(0, l):
		for k in range(j + 1, l):
			if f[j] + f[k] == c:
				found = True
				x = j
				y = k
				break
		if found:
			break
	print(x + 1, y + 1)


t = int(input())
for p in range(t):
	c = int(input())
	l = int(input())
	line = input().split()
	f = [int(line[i]) for i in range(l)]
	for i in range(l):
		try:
			d = f[i + 1:].index(c - f[i]) + 1
		except ValueError:
			d = -1
		if d != -1:
			print(str(i + 1) + ' ' + str(i + d + 1))
			break


def key1(a):
	return a[0]
T = int(input())
for t in range(T):
	c = int(input())
	d = int(input())
	e = [int(b) for b in input().split()]
	for i in range(len(e)):
		if c - e[i] in e:
			j = e.index(c - e[i])
			if j != i:
				print(min(i + 1, j + 1), max(i + 1, j + 1))
				break


t = int(input())
for i in range(t):
	c = int(input())
	l = int(input())
	flavors = [int(j) for j in input().split()]
	for j in range(len(flavors)):
		if flavors[j] < c:
			for k in range(j + 1, len(flavors)):
				if flavors[j] + flavors[k] == c:
					print(str(j + 1) + ' ' + str(k + 1))


T = int(input())
i = 0
while i < T:
	C = int(input())
	L = int(input())
	listL = input().split()
	listL = [int(i) for i in listL]
	j = 0
	end = 0
	while j < L:
		k = j + 1
		while k < L:
			if listL[j] + listL[k] == C:
				print(str(j + 1) + ' ' + str(k + 1))
				end = 1
				break
			k += 1
		if end == 1:
			break
		j += 1
	i += 1


n = int(input())
cases = []
for i in range(0, n):
	c = int(input())
	l = int(input())
	f = list(map(int, input().split()))
	cases.append([c, l, f])

def look(l, c):
	for n1 in range(0, len(l)):
		for n2 in range(0, len(l)):
			if n1 == n2:
				continue
			if l[n1] + l[n2] == c:
				return [str(n1 + 1), str(n2 + 1)]
for case in cases:
	print(' '.join(look(case[2], case[0])))


def function(ice_costs, money):
	ice_costs = list(enumerate(ice_costs))
	possible = [i for i in ice_costs if int(i[1]) < money]
	counter = 0
	additions = [i for i in possible for x in possible if int(i[1]) + int(x[1]) == money and int(i[0]) != int(x[0])]
	index = [str(i[0] + 1) for i in additions]
	print(' '.join(index))
T = int(input())
for i in range(T):
	money = int(input())
	number = int(input())
	ice_costs = str(input())
	ice_costs = ice_costs.split()
	function(ice_costs, money)


t = int(input())
for p in range(0, t):
	m = int(input())
	n = int(input())
	vals = [int(i) for i in input().strip().split()]
	for q in range(0, n):
		temp = q
		for r in range(q + 1, n):
			if vals[temp] + vals[r] == m:
				print(temp + 1, r + 1)
				break


for i in range(int(input())):
	M = int(input())
	N = int(input())
	cost = [int(k) for k in input().split()]
	res = []
	for j in range(len(cost)):
		for z in range(len(cost)):
			if j != z and cost[z] + cost[j] == M:
				res.append(j)
				res.append(z)
				break
		if len(res) > 0:
			break
	res.sort()
	print(str(res[0] + 1) + ' ' + str(res[1] + 1))


import sys
from itertools import combinations

def calc(money, flavorCosts):
	for ((i1, v1), (i2, v2)) in combinations(enumerate(flavorCosts, 1), 2):
		if money == v1 + v2:
			return (i1, i2)
cases = int(sys.stdin.readline())
for i in range(cases):
	money = int(sys.stdin.readline())
	flavorCount = int(sys.stdin.readline())
	flavorString = sys.stdin.readline()
	flavors = (int(cost) for cost in flavorString.split())
	solution = calc(money, flavors)
	if solution is not None:
		print('{0} {1}'.format(*solution))


T = int(input())
for t in range(T):
	M = int(input())
	N = int(input())
	lst = input().split()
	lst = list(map(int, lst))
	for i in range(N - 1):
		diff = M - lst[i]
		for j in range(i + 1, N):
			if diff == lst[j]:
				print(i + 1, j + 1)
				break


T = int(input())
for i in range(T):
	m = int(input())
	n = int(input())
	cs = list(map(int, input().split()))
	for j in range(n):
		try:
			k = j + 1 + cs[j + 1:].index(m - cs[j])
			print(j + 1, k + 1)
			break
		except ValueError:
			pass


import sys
numtests = int(sys.stdin.readline())
tests = []
for times in range(numtests):
	M = int(sys.stdin.readline())
	N = int(sys.stdin.readline())
	array = [int(x) for x in sys.stdin.readline().split(' ')]
	tests.append((M, N, array))
for times in range(numtests):
	M = tests[times][0]
	N = tests[times][1]
	array = tests[times][2]
	for i in range(N):
		base = array[i]
		for j in range(i + 1, N):
			if base + array[j] == M:
				print(i + 1, j + 1)
				break


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		m = int(sys.stdin.readline())
		n = int(sys.stdin.readline())
		prices = [int(i) for i in sys.stdin.readline().split()]
		for i in range(n):
			for j in range(i, n):
				if prices[i] + prices[j] == m and i != j:
					print(i + 1, j + 1)
main()


import sys

class IceCreamParlorCase:

	def __init__(self, totalAmount, costs):
		self.totalAmount = totalAmount
		self.costs = []
		i = 1
		for cost in costs:
			if cost < totalAmount:
				self.costs.append((cost, i))
			i = i + 1
		self.costs.sort(key=lambda x: x[0])

	def solve(self):
		numCosts = len(self.costs)
		for i in range(0, numCosts):
			for j in range(i + 1, numCosts):
				if self.costs[i][0] + self.costs[j][0] == self.totalAmount:
					return sorted([self.costs[i][1], self.costs[j][1]])
numCases = int(sys.stdin.readline())
for i in range(0, numCases):
	totalAmount = int(sys.stdin.readline())
	numFlavors = int(sys.stdin.readline())
	costs = [int(x) for x in sys.stdin.readline().split(' ')]
	testCase = IceCreamParlorCase(totalAmount, costs)
	result = testCase.solve()
	print('{0} {1}'.format(result[0], result[1]))


T = int(input())
for t in range(0, T):
	M = int(input())
	N = int(input())
	C = [int(x) for x in input().split(' ')]
	D = [(C[i], i + 1) for i in range(0, N)]
	D.sort()
	(i, j) = (0, N - 1)
	while i < j:
		m = D[i][0] + D[j][0]
		if m == M:
			(di, dj) = (D[i][1], D[j][1])
			if di > dj:
				(di, dj) = (dj, di)
			print(str(di) + ' ' + str(dj))
			break
		if m < M:
			i += 1
		else:
			j -= 1
	if i >= j:
		print(D)


t = int(input())
c = 0
while t > c:
	m = int(input())
	n = int(input())
	ic = input().split(' ')
	ice = [int(i) for i in ic]
	ind = []
	bol = False
	for x in range(n):
		for k in range(n):
			if ice[x] + ice[k] == m and k != x:
				print(x + 1, k + 1)
				bol = True
				break
		if bol == True:
			break
	c += 1


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	M = int(sys.stdin.readline())
	N = int(sys.stdin.readline())
	C = list(map(int, sys.stdin.readline().split()))
	for (i, c) in enumerate(C[:-1]):
		for j in range(i + 1, len(C)):
			if C[j] == M - c:
				print(i + 1, j + 1)
				break


t = int(input())
for _ in range(t):
	m = int(input())
	n = int(input())
	c = list(map(int, input().split(' ')))
	for i in range(n):
		c[i] = [c[i], i]
	c.sort()
	k = m - c[0][0]
	j = n - 1
	while c[j][0] > k:
		j -= 1
	i = 0
	while i < j:
		k = m - c[j][0]
		while c[i][0] < k:
			i += 1
		if c[i][0] == k:
			break
		j -= 1
	a = c[i][1]
	b = c[j][1]
	if a > b:
		(a, b) = (b, a)
	print(a + 1, b + 1)


N = int(input())
for x in range(0, N):
	cash = int(input())
	cases = int(input())
	flavors = input().split(' ')
	flavors = [int(x) for x in flavors]
	for x in range(0, len(flavors)):
		for y in range(x + 1, len(flavors)):
			if flavors[x] + flavors[y] == cash:
				print(str(x + 1) + ' ' + str(y + 1))
				break


T = int(input().strip())
for i in range(T):
	money = int(input().strip())
	num_flaors = int(input().strip())
	flavor_prices = list(map(int, input().strip().split()))
	pair_prices = {}
	done = False
	for (i, p1) in enumerate(flavor_prices):
		for (j, p2) in enumerate(flavor_prices):
			if p1 + p2 == money and i != j:
				print(*sorted([i + 1, j + 1]))
				done = True
				break
		if done:
			break


T = int(input())
for i in range(0, T):
	M = int(input())
	N = int(input())
	X = [int(x) for x in input().split(' ')]
	breaker = 'false'
	for j in range(0, len(X)):
		for k in range(j, len(X)):
			if j != k:
				if X[j] + X[k] == M:
					print(j + 1, end=' ')
					print(k + 1)
					breaker = 'true'
					break
		if breaker == 'true':
			break


import sys
import math
t = int(sys.stdin.readline())
for i in range(t):
	m = int(sys.stdin.readline())
	n = int(sys.stdin.readline())
	cost = [int(i) for i in sys.stdin.readline().split()]
	invCost = []
	indices = []
	for i in range(n):
		invCost.append(m - cost[i])
	for i in range(n):
		try:
			j = cost.index(invCost[i])
			if j != i:
				indices.append(i + 1)
				indices.append(j + 1)
				break
		except ValueError:
			continue
	indices.sort()
	print(str(indices[0]) + ' ' + str(indices[1]))


numCases = int(input())
for _ in range(numCases):
	m = int(input())
	n = int(input())
	costs = [int(x) for x in input().split()]
	costSet = set(costs)
	for (n, cost) in enumerate(costs):
		if m - cost in costSet and costs.index(m - cost) != n:
			print(str(min(n, costs.index(m - cost)) + 1) + ' ' + str(max(n, costs.index(m - cost)) + 1))
			break


cases = int(input())
for i in range(0, cases):
	sum = int(input())
	arr_len = int(input())
	arr = input()
	arr = arr.split(' ')
	for j in range(0, len(arr)):
		arr[j] = int(arr[j])
	index1 = 0
	index2 = 0
	for l in range(0, len(arr)):
		for m in range(l + 1, len(arr)):
			if arr[l] + arr[m] == sum:
				index1 = l
				index2 = m
	print(index1 + 1, index2 + 1)


num_testcase = int(input())
for i_testcase in range(num_testcase):
	num_dollars = int(input())
	num_flavors = int(input())
	prices = eval('[%s]' % ','.join(input().split()))
	for i_flavor in range(num_flavors):
		for j_flavor in range(i_flavor + 1, num_flavors):
			if prices[i_flavor] + prices[j_flavor] == num_dollars:
				print(i_flavor + 1, j_flavor + 1)


import sys
T = int(sys.stdin.readline())
for case in range(T):
	M = int(sys.stdin.readline())
	N = int(sys.stdin.readline())
	cis = [int(X) for X in sys.stdin.readline().split()]
	match = dict()
	for (i, ci) in enumerate(cis):
		if ci in match:
			print(match[ci] + 1, i + 1)
			break
		match[M - ci] = i


class Blop:

	def __init__(self, index, value):
		self.index = index
		self.value = value
T = int(input())
for t in range(T):
	M = int(input())
	N = int(input())
	ar = [Blop(i, int(v)) for (i, v) in enumerate(str(input()).split())]
	ar.sort(key=lambda x: x.value)
	(i, j) = (0, 0)
	for (k, a) in enumerate(ar):
		for b in ar[k + 1:]:
			if a.value + b.value < M:
				continue
			if a.value + b.value > M:
				break
			if a.value + b.value == M:
				(i, j) = (a.index + 1, b.index + 1)
				break
		if i != 0:
			break
	if i > j:
		(i, j) = (j, i)
	print(i, j)


T = int(input())
for Ti in range(T):
	M = int(input())
	N = int(input())
	icecreams = [int(v) for v in input().split()]
	m = {}
	i = 1
	for icecream in icecreams:
		if icecream not in m:
			m[icecream] = []
		m[icecream].append(i)
		i += 1
	for icecream in icecreams:
		another = M - icecream
		if another in m:
			if icecream == another:
				if len(m[icecream]) > 1:
					print(m[icecream][0], m[icecream][1])
					break
			else:
				print(m[icecream][0], m[another][0])
				break


T = int(input())
for t in range(T):
	M = int(input())
	N = int(input())
	prices = input().split()
	pricesDict = dict()
	for i in range(N):
		if prices[i] in pricesDict:
			pricesDict[prices[i]].append(i)
		else:
			pricesDict[prices[i]] = [i]
	shouldBreak = False
	for i in range(N):
		targetValue = str(M - int(prices[i]))
		if targetValue in pricesDict:
			for j in pricesDict[targetValue]:
				if i != j:
					print('{} {}'.format(i + 1, int(j) + 1))
					shouldBreak = True
					break
		if shouldBreak:
			break


def prog():
	for i in range(int(input())):
		(m, n) = (int(input()), int(input()))
		costs = [int(x) for x in str(input()).split()]
		for i in range(len(costs) - 1):
			for j in range(len(costs) - (i + 1)):
				if costs[i] + costs[j + i + 1] == m:
					print('%i %i' % (i + 1, j + i + 2))
prog()


a = int(input())
for i in range(a):
	m = int(input())
	n = int(input())
	x = input().split(' ')
	x = [int(i) for i in x]
	for j in range(len(x)):
		for k in range(j + 1, len(x)):
			if x[j] + x[k] == m:
				print(j + 1, k + 1, sep=' ')


for i in range(int(input())):
	M = int(input())
	N = int(input())
	cs = list(map(int, input().split()))
	for j in range(N):
		try:
			k = cs[j + 1:].index(M - cs[j])
			print(str(j + 1) + ' ' + str(k + j + 2))
		except:
			pass


import itertools
N = int(input())
for i in range(N):
	M = int(input())
	flavor_count = int(input())
	costs = [int(x) for x in input().split(' ')]
	found = False
	for (f_i, first) in enumerate(costs):
		for s_i in range(f_i + 1, len(costs)):
			if first + costs[s_i] == M:
				print(' '.join([str(f_i + 1), str(s_i + 1)]))
				found = True
				break
		if found:
			break


for l in range(int(input())):
	m = int(input())
	n = int(input())
	arr = [int(x) for x in input().split()]
	d = dict()
	for (i, x) in enumerate(arr):
		if x in d:
			continue
		d[x] = i
	for (i, x) in enumerate(arr):
		if m - x in d:
			if d[m - x] == i:
				continue
			(x, y) = (d[m - x] + 1, i + 1)
			x1 = min(x, y)
			y1 = max(x, y)
			print(x1, y1)
			break


def sumFindDefinition(sum_no, list_values):
	for first in range(len(list_values)):
		for second in range(first + 1, len(list_values)):
			if int(list_values[first]) + int(list_values[second]) == sum_no:
				print(first + 1, second + 1)
for i in range(int(input())):
	sum_number = int(input())
	no_of_values = int(input())
	list_of_values = input().split()
	sumFindDefinition(sum_number, list_of_values)


def checkIndex(costs, money, index):
	i = 0
	while i < len(costs):
		if i != index and costs[i] + costs[index] == money:
			return i
		i += 1
	return -1

def getIndices(costs, money):
	i = 0
	while i < len(costs):
		indexCheck = checkIndex(costs, money, i)
		if indexCheck >= 0:
			index1 = i + 1
			index2 = indexCheck + 1
			return str(min(index1, index2)) + ' ' + str(max(index1, index2))
		i += 1
t = int(input())
assert 1 <= t <= 50
for i in range(t):
	money = int(input())
	assert 2 <= money <= 10000
	flavors = int(input())
	assert 2 <= flavors <= 10000
	costs = input().strip().split(' ')
	assert len(costs) == flavors
	for i in range(flavors):
		costs[i] = int(costs[i])
	print(getIndices(costs, money))


test_cases = int(input())
for i in range(test_cases):
	cash = int(input())
	input()
	prices = [int(x) for x in input().split(' ')]
	for a in range(len(prices) - 1):
		for b in range(a + 1, len(prices)):
			if prices[a] + prices[b] == cash:
				print(str(a + 1) + ' ' + str(b + 1))


x = int(input())
for i in range(x):
	flag = True
	m = int(input())
	n = int(input())
	cost = list(map(int, input().split()))
	for i in range(n):
		for j in range(n):
			if i != j and cost[i] + cost[j] == m:
				print(str(i + 1) + ' ' + str(j + 1))
				flag = False
				break
		if flag == False:
			break


from itertools import combinations

def do_the_work(key, prices):
	for index1 in range(len(prices)):
		for index2 in range(index1 + 1, len(prices)):
			if prices[index1] + prices[index2] == m:
				return [index1 + 1, index2 + 1]
for case in range(int(input())):
	m = int(input())
	n = int(input())
	prices = [int(x) for x in input().split(' ')]
	print(*do_the_work(m, prices))


def findPairWithSum(items, total):
	length = len(items)
	for i in range(0, length):
		for j in range(i + 1, length):
			if items[i] + items[j] == total:
				return (i, j)
numTestCases = int(input())
for i in range(0, numTestCases):
	m = int(input())
	n = int(input())
	items = [int(x) for x in input().split()]
	(i, j) = findPairWithSum(items, m)
	print(i + 1, j + 1)


T = int(input())
for case in range(T):
	m = int(input())
	n = int(input())
	costs = [int(i) for i in input().split(' ')]
	stop = cnt = 0
	while not stop:
		curnum = costs[cnt]
		if curnum < m:
			if m - curnum in costs[cnt + 1:]:
				ans = costs[cnt + 1:].index(m - curnum) + cnt + 1
				stop = 1
		cnt += 1
		if cnt == len(costs):
			stop = 1
			ans = -1
	print(cnt, ans + 1)


t = int(input())
for _ in range(t):
	m = int(input())
	n = int(input())
	fl = [int(x) for x in input().split()]
	(fi, si) = (-1, -1)
	for i in range(n):
		for j in range(i + 1, n):
			if fl[i] + fl[j] == m:
				(fi, si) = (i, j)
				break
		if fi > 0 and si > 0:
			break
	print(str(fi + 1) + ' ' + str(si + 1))


for i in range(int(input())):
	(m, n) = (int(input()), int(input()))
	a = [int(e) for e in input().split()]
	for j in range(n):
		for k in range(j + 1, n):
			if a[j] + a[k] == m:
				print(j + 1, k + 1)


def find_indexes(cs, m):
	index = 1
	ice_creams = {}
	for c in cs:
		if m - c in ice_creams:
			return (ice_creams[m - c], index)
		ice_creams[c] = index
		index += 1
t = int(input())
for i in range(t):
	m = int(input())
	n = int(input())
	cs = [int(c) for c in input().split()]
	(a, b) = find_indexes(cs, m)
	print(a, b)


def alpha(l, m):
	l.sort()
	i = 0
	while i < len(l):
		if l[i] <= m - l[0]:
			i = i + 1
		elif l[i] > m - l[0]:
			break
	return l[0:i]

def br(l, m):
	if m % 2 != 0:
		lis = []
		a = alpha(l, m)
		b = int(m / 2) + 1
		i = 0
		while i < len(a):
			if a[i] < b:
				i = i + 1
			elif a[i] >= b:
				t = a[:i]
				p = a[i:]
				lis.append(t)
				lis.append(p)
				break
		return lis
	elif m % 2 == 0:
		lis = []
		a = alpha(l, m)
		b = int(m / 2)
		i = 0
		while i < len(a):
			if a[i] < b:
				i = i + 1
			elif a[i] == b:
				t = a[:i + 1]
				p = a[i + 1:]
				lis.append(t)
				lis.append(p)
				break
			elif a[i] > b:
				t = a[:i]
				p = a[i:]
				lis.append(t)
				lis.append(p)
				break
		return lis

def hr(l, m):
	z = l[:]
	q = br(l, m)
	t = q[0]
	p = q[1]
	j = 0
	s = ''
	while j < len(t) and len(s.split()) < 2:
		k = 0
		while k < len(p):
			if t[j] + p[k] == m:
				if t[j] == p[k]:
					s = s + '%d %d' % (z.index(t[j]) + 1, z[z.index(t[j]) + 1:].index(p[k]) + 2 + z.index(t[j]))
					break
				else:
					if z.index(t[j]) <= z.index(p[k]):
						s = s + '%d %d' % (z.index(t[j]) + 1, z.index(p[k]) + 1)
					else:
						s = s + '%d %d' % (z.index(p[k]) + 1, z.index(t[j]) + 1)
					break
			else:
				k = k + 1
		j = j + 1
	return s
num = int(input())
lis = []
for i in range(1, num + 1):
	li = [int(input()), int(input()), [int(x) for x in input().split()]]
	lis.append(li)
for c in lis:
	print(hr(c[2], c[0]))


t = int(input())
for _ in range(t):
	m = int(input())
	n = int(input())
	a = list(map(int, input().split()))
	vals = {}
	lastm2 = None
	for (i, x) in enumerate(a):
		if x in vals and x + x == m:
			lastm2 = i + 1
		else:
			vals[x] = i + 1
	if lastm2:
		print(vals[m // 2], lastm2)
	else:
		for x in range(1, m // 2 + 1):
			if x in vals and m - x in vals:
				print(min(vals[x], vals[m - x]), max(vals[x], vals[m - x]))
				break


import collections
T = int(input())
for i in range(T):
	target = int(input())
	input()
	costs = [int(val) for val in input().split()]
	indices = {}
	for (i, e) in enumerate(costs):
		if e in indices:
			indices[e].append(i + 1)
		else:
			indices[e] = []
			indices[e].append(i + 1)
	for e in indices.keys():
		if target - e in indices:
			if e + e == target and len(indices[e]) >= 2:
				print('%d %d' % (indices[e][0], indices[e][1]))
				break
			elif e + e != target:
				small = min(indices[e][0], indices[target - e][0])
				big = max(indices[e][0], indices[target - e][0])
				print('%d %d' % (small, big))
				break


def tc(n, m, arr):
	for i in range(0, n - 1):
		for j in range(i + 1, n):
			if arr[i] + arr[j] == m:
				print(i + 1, j + 1)
				return
t = int(input())
for _ in range(t):
	m = int(input())
	n = int(input())
	arr = [int(x) for x in input().split()]
	tc(n, m, arr)


t = int(input())
while t:
	t -= 1
	m = int(input())
	input()
	lst = [int(x) for x in input().strip().split(' ')]
	sort_lst = sorted(lst)
	(i, j) = (0, len(sort_lst))
	while i < j:
		num = sort_lst[i]
		req_num = m - num
		while sort_lst[j - 1] > req_num:
			j -= 1
		if sort_lst[j - 1] == req_num:
			break
		i += 1
	for p in range(len(lst)):
		if lst[p] == sort_lst[i] or lst[p] == sort_lst[j - 1]:
			print(p + 1, end=' ')
	print()


def iceCreamPalor(costs, target):
	costs = tuple(sorted(((c, i + 1) for (i, c) in enumerate(costs))))
	begin = 0
	end = len(costs) - 1
	while begin < end:
		currentCost = costs[begin][0] + costs[end][0]
		if currentCost < target:
			begin += 1
		elif currentCost > target:
			end -= 1
		else:
			return tuple(sorted((costs[begin][1], costs[end][1])))
	return None
T = int(input().strip())
for t in range(T):
	M = int(input().strip())
	N = int(input().strip())
	costs = tuple((int(c) for c in input().strip().split()))
	result = iceCreamPalor(costs, M)
	print(' '.join((str(i) for i in result)))


def find_flavors(m, arr):
	for (index_i, i) in enumerate(arr):
		for (index_j, j) in enumerate(arr):
			if index_i != index_j and i + j == m:
				return '{} {}'.format(index_i + 1, index_j + 1)

def main():
	t = int(input())
	for _ in range(t):
		m = int(input())
		input()
		arr = [int(i) for i in input().split()]
		print(find_flavors(m, arr))
main()


def printIndex(i, j):
	if i > j:
		tmp = i
		i = j
		j = tmp
	print(str(i) + ' ' + str(j))

def main():
	for i in range(int(input())):
		M = int(input())
		N = int(input())
		nums = list(map(int, input().split(' ')))
		mp = {}
		for i in range(N):
			num = nums[i]
			if num in mp:
				mp[num].append(i + 1)
			else:
				mp[num] = [i + 1]
		for i in nums:
			if i > M:
				continue
			diff = M - i
			if diff == i:
				if len(mp[i]) >= 2:
					printIndex(mp[i][0], mp[i][1])
					break
			elif diff in mp:
				printIndex(mp[i][0], mp[diff][0])
				break
main()


t = int(input())
for l in range(t):
	m = int(input())
	n = int(input())
	ar = [int(i) for i in input().strip().split()]
	for i in range(len(ar)):
		for j in range(i, len(ar)):
			if i != j:
				if ar[i] + ar[j] == m:
					if i > j:
						print(str(j + 1) + ' ' + str(i + 1))
					else:
						print(str(i + 1) + ' ' + str(j + 1))


def find(tot, arr):
	for i in range(len(arr)):
		fval = arr[i]
		for j in range(i + 1, len(arr)):
			if arr[j] + fval == tot:
				print(i + 1, j + 1)
T = int(input())
for x in range(T):
	m = int(input())
	n = int(input())
	arr = list(map(int, input().split()))
	find(m, arr)


t = int(input())

def doIceCream():
	money = int(input())
	num_flavors = int(input())
	flavor_costs = list(map(int, input().split(' ')))
	for i in range(num_flavors):
		for j in range(num_flavors):
			if not i == j:
				if flavor_costs[i] + flavor_costs[j] == money:
					print(i + 1, j + 1)
					return
for i in range(t):
	doIceCream()


import itertools
t = int(input())
for _ in range(t):
	m = int(input())
	n = int(input())
	arr = list(map(int, input().split()))
	(a, b) = list(filter(lambda x: x[0] + x[1] == m, itertools.combinations(arr, 2)))[0]
	a_index = arr.index(a) + 1
	if a == b:
		print(a_index, arr.index(b, a_index) + 1)
	else:
		(a_index, b_index) = sorted([a_index, arr.index(b) + 1])
		print(a_index, b_index)


__author__ = 'danielbaeck'
import math
import itertools
t = int(input())
for i in range(t):
	m = int(input())
	n = int(input())
	p = [int(x) for x in input().split(' ')]
	for c in itertools.combinations(p, 2):
		if sum(c) == m:
			first = str(p.index(c[0]) + 1)
			p.remove(c[0])
			print(first + ' ' + str(p.index(c[1]) + 2))
			break


T = int(input().strip())
for i in range(T):
	M = int(input().strip())
	N = int(input().strip())
	c = [int(i) for i in input().strip().split(' ')]
	flag = 0
	for j in range(N):
		for k in range(j + 1, N):
			if c[j] + c[k] == M:
				print(j + 1, k + 1)
				flag = 1
				break
		if flag == 1:
			break


t = int(input())
cases = [(int(input()), int(input()), list(map(int, input().split()))) for i in range(t)]
for (n, _, prices) in cases:
	for (i, j) in ((x, y) for x in range(len(prices) - 1) for y in range(x + 1, len(prices))):
		if prices[i] + prices[j] == n:
			print(i + 1, j + 1)
			break


test = int(input())
for t in range(test):
	m = int(input())
	n = int(input())
	a = list(map(int, input().split()))
	x = {a[0]: [0]}
	i = 1
	while i < n:
		if x.get(a[i]) != None:
			x[a[i]].append(i)
		else:
			x[a[i]] = [i]
		i += 1
	i = 0
	while i < n:
		if x.get(m - a[i]) != None:
			if m - a[i] != a[i]:
				print('%d %d' % (i + 1, x[m - a[i]][0] + 1))
				break
			elif len(x[m - a[i]]) != 1:
				print('%d %d' % (i + 1, x[m - a[i]][1] + 1))
				break
		i = i + 1


t = int(input())
for _ in range(t):
	m = int(input())
	input()
	s = {}
	for (i, v) in enumerate(input().split()):
		v = int(v)
		if m - v in s:
			print(s[m - v], i + 1)
			break
		else:
			s[v] = i + 1


T = int(input())
for testcase in range(T):
	M = int(input())
	N = int(input())
	C = [int(x) for x in input().strip().split(' ')]
	array = []
	for i in range(len(C)):
		array.append((C[i], i + 1))
	array.sort(key=lambda x: x[0])
	(start, end) = (0, len(array) - 1)
	while start < end:
		added = array[start][0] + array[end][0]
		if added < M:
			start += 1
		elif added > M:
			end -= 1
		else:
			(index_1, index_2) = (array[start][1], array[end][1])
			print('{} {}'.format(min(index_1, index_2), max(index_1, index_2)))
			break


from collections import defaultdict
no_of_test = int(input())
for x in range(0, no_of_test):
	money = int(input())
	no_of_flavour = int(input())
	cost_of_flavour = list(map(int, input().split(' ')))
	found = False
	for i in range(0, no_of_flavour):
		for j in range(i + 1, no_of_flavour):
			ice_cream_cost = cost_of_flavour[i] + cost_of_flavour[j]
			if money == ice_cream_cost:
				found = True
				print(i + 1, j + 1)
				break
		if found:
			break


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	M = int(sys.stdin.readline())
	N = int(sys.stdin.readline())
	C = list(map(int, sys.stdin.readline().split()))
	for (i, c) in enumerate(C[:-1]):
		for j in range(i + 1, len(C)):
			if C[j] == M - c:
				print(i + 1, j + 1)
				break


def find_flavors(lst, s):
	for (i, _) in enumerate(lst):
		for (j, _) in enumerate(lst):
			if i != j and lst[i] + lst[j] == s:
				return (i + 1, j + 1)
t = int(input())
for _ in range(t):
	s = int(input())
	_ = input()
	lst = [int(el) for el in input().strip().split()]
	print('%s %s' % find_flavors(lst, s))


T = int(input().strip())
for i in range(T):
	M = int(input().strip())
	input()
	A = [int(j) for j in input().split(' ')]
	for k in range(len(A)):
		for q in range(k, len(A)):
			if k != q and A[k] + A[q] == M:
				print(k + 1, q + 1)
				break


t = int(input())
while t > 0:
	m = int(input())
	n = int(input())
	c = []
	s = input()
	for str in s.split():
		c.append(int(str))
	for i in range(0, n):
		l = m - c[i]
		if l > 0 and l in c and (c.index(l) != i):
			ind = c.index(l)
			if i > ind:
				(i, ind) = (ind, i)
			print(i + 1, end=' ')
			print(ind + 1)
			break
	t = t - 1


t = 0
t = int(input())
for i in range(0, t):
	c = []
	left = 0
	m = int(input())
	n = int(input())
	k = input()
	for str in k.split():
		c.append(int(str))
	for j in range(0, n):
		left = m - c[j]
		while left < 0:
			j = j + 1
			left = m - c[j]
		if left in c and j != c.index(left):
			if j < c.index(left):
				print(j + 1, end=' ')
				print(c.index(left) + 1)
				break
			else:
				print(c.index(left) + 1, end=' ')
				print(j + 1)
				break
	for j in range(0, n):
		c[j] = 0


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	M = int(sys.stdin.readline())
	N = int(sys.stdin.readline())
	C = list(map(int, sys.stdin.readline().split()))
	for (i, c) in enumerate(C[:-1]):
		for j in range(i + 1, len(C)):
			if C[j] == M - c:
				print(i + 1, j + 1)
				break


tests = int(input())
for test in range(tests):
	M = int(input())
	N = input()
	flavors = [int(price) for price in input().split()]
	found = False
	for price1 in range(len(flavors)):
		for price2 in range(price1 + 1, len(flavors)):
			if flavors[price1] + flavors[price2] == M:
				bought = [price1 + 1, price2 + 1]
				found = True
				break
		if found == True:
			break
	print(bought[0], bought[1])


for i in range(int(input())):
	target = int(input())
	loop = int(input())
	costs = input().split(' ')
	cur = 0
	done = False
	for j in range(loop - 1):
		for k in range(j + 1, loop):
			if int(costs[j]) + int(costs[k]) == target:
				print(str(j + 1) + ' ' + str(k + 1))
				done = True
				break
		if done:
			break


LEFT = 0
RIGHT = 1
IN_ORDER = 0
PRE_ORDER = 1
POST_ORDER = 2
FILEREADER = None
RED = 0
BLACK = 1

class BSTNode:

	def __init__(self, k=None, v=None, f=None):
		self.key = k
		self.value = v
		self.flag = f
	LeftKid = None
	RightKid = None
	Parent = None

	def set_as(self, node):
		if self.key != None:
			return
		self.key = node.key
		self.value = node.value
		self.LeftKid = node.LeftKid
		self.RightKid = node.RightKid
		self.flag = node.flag

	def numkids(self):
		n = 0
		if self.LeftKid != None:
			n = n + 1
		if self.RightKid != None:
			n = n + 1
		return n

	def printNode(self):
		if self == None:
			return
		print('key: ', self.key, 'color: ', self.flag)
		if self.LeftKid != None:
			print('/')
		if self.RightKid != None:
			print('\\')

class BSTree:

	def __init__(self, function_collection_class, keys_list=None):
		self.BSTType = function_collection_class
		self.TreeRoot = BSTNode(None, None, None)
		if keys_list != None:
			try:
				for i in keys_list:
					self.insertkey(i)
			except Exception as e:
				print('tree building failed')
				self.printTree2()
				raise e

	def searchkey(self, key, root=None):
		n = root
		if not n:
			n = self.TreeRoot
		while n and n.key != key:
			if n.key > key:
				n = n.LeftKid
			elif n.key < key:
				n = n.RightKid
		return n

	def insertkey(self, key):
		n = None
		try:
			n = BSTNode(*key)
		except:
			n = BSTNode(key)
		self.BSTType._insert(n, self.TreeRoot)
		while self.TreeRoot.Parent:
			self.TreeRoot = self.TreeRoot.Parent

	def insertOrUpdate(self, key, value):
		if not self.TreeRoot.key:
			self.insertkey((key, value))
			return
		n = self.searchkey(key)
		if n:
			n.value = value
		else:
			self.insertkey((key, value))

	def insertOrAppend(self, key, value):
		if not self.TreeRoot.key:
			self.insertkey((key, [value]))
			return
		n = self.searchkey(key)
		if n:
			n.value.append(value)
		else:
			self.insertkey((key, [value]))

	def delkey(self, key):
		self.BSTType._delnode(BSTNode(key), self.TreeRoot)

	def minKey(self):
		n = self.BSTType._minnode(self.TreeRoot)
		if n:
			return n.key
		else:
			return None

	def maxKey(self):
		n = self.BSTType._maxnode(self.TreeRoot)
		if n:
			return n.key
		else:
			return None

	def minNode(self):
		return self.BSTType._minnode(self.TreeRoot)

	def maxNode(self):
		return self.BSTType._maxnode(self.TreeRoot)

	def size(self):
		return self.BSTType._size(self.TreeRoot)

	def buildBST(self, keylist):
		for key in keylist:
			self.insertkey(key)

	def printTree(self):
		print('======TREE======')
		self.BSTType._printTree(self.TreeRoot)

	def printTree2(self):
		print('======TREE======')
		self.BSTType._printTreeByLevel(self.TreeRoot)

	def serialize(self, filename):
		self.BSTType._serialize(self.TreeRoot, filename)

	def deserialize(self, filename):
		print('deserialize')
		nodelist = self.BSTType._deserialize_reader(filename)
		f = lambda x: BSTNode(*x)
		nn = list(map(f, nodelist))
		self.BSTType._deserialize(nn, self.TreeRoot)

class searchinfo:

	def __init__(self, k, p, s):
		self.kid = k
		self.parent = p
		self.side = s

	def printsi(self):
		k = 'None'
		p = 'None'
		if self.kid != None:
			k = self.kid.key
		if self.parent != None:
			p = self.parent.key
		print(k, p, self.side)

class SimpleBSTreeFunctions:

	def _insert(self, node, root):
		if root.key == None:
			root.set_as(node)
			root = node
			return
		t = search_extra(node, root)
		if t.kid == None:
			t.kid = node
			setnode(t)

	def _delnode(self, node, root):
		_del(node, root)

	def _size(self, root):
		return traverse(root, lambda x: 0 if x == None else 1, lambda x, y, z: x + y + z if y != None and z != None else x)

	def _minnode(self, root):
		n = root
		while n.LeftKid:
			n = n.LeftKid
		return n

	def _maxnode(self, root):
		n = root
		while n.RightKid:
			n = n.RightKid
		return n

	def _deserialize_reader(self, filename):
		try:
			f = open(filename, 'r')
			nodes = f.readlines()
			f.close()
			return list(map(deserialize_reader_helper, nodes))
		except:
			raise IOError('file cannot be opened')

	def _deserialize(self, nodelist, root):
		deserialize_helper(nodelist, root, None, None)

	def _serialize(self, root, filename):
		global FILEREADER
		FILEREADER = open(filename, 'w')
		traverse(root, serialize_node_function, None, PRE_ORDER)
		FILEREADER.close()

	def _printTree(self, root):
		traverse(root, lambda x: x.printNode() if x else None, None, PRE_ORDER)

	def _printTreeByLevel(self, root):
		acc_result = {'level': 0, 'levellist': [[]]}
		treestring = BFS(root, setlevel, accumulate_treestring, acc_result)
		lev = 0
		for i in treestring['levellist']:
			a = ''
			b = ''
			for j in i:
				a = a + str(j[0]) + ',' + str(j[1])
				b = b + str(j[2])
				for k in range(lev):
					a = a + '   '
					b = b + '   '
			print(a)
			print(b)
			lev = lev + 1

class RedAndBlackTreeFunctions(SimpleBSTreeFunctions):

	def _insert(self, node, root):
		if root.key == None:
			root.set_as(node)
			root.flag = BLACK
			return
		si = search_extra(node, root)
		if si.kid == None:
			node.flag = RED
			si.kid = node
			setnode(si)
		else:
			return
		cn = si.kid
		cp = si.parent
		while cn.flag == RED and cp != None and (cp.flag == RED):
			if uncle(cn) != None and uncle(cn).flag == RED:
				cg = cp.Parent
				cp.flag = BLACK
				uncle(cn).flag = BLACK
				if cg.key != root.key:
					cg.flag = RED
				cn = cg
				if cg.Parent != None:
					cp = cn.Parent
					cg = cp.Parent
			elif cn.flag == RED and uncle(cn) == None or uncle(cn).flag == BLACK:
				if get_side(cn) == get_side(cp):
					tilt(cp)
					cp = cn.Parent
				else:
					tilt(cn)
					tilt(cn)
					cp = cn.Parent
			else:
				print('cn')
				cn.printNode()
				print('cp')
				cp.printNode()
				print('cg')
				cg.printNode()
				print('cn uncle')
				uncle(cn).printNode()
				raise RuntimeError('I shouldnt be here')

	def deserialize_reader(self, filename):
		return [(5, None, BLACK), (2, None, RED), (1, None, BLACK), (3, None, BLACK), (12, None, RED), (7, None, BLACK), (8, None, RED), (15, None, BLACK), (12, None, RED)]

	def _printTreeByLevel(self, root):
		acc_result = {'level': 0, 'levellist': [[]]}
		treestring = BFS(root, setlevel, accumulate_treestring2, acc_result)
		print('levels:', len(treestring['levellist']))
		for i in treestring['levellist']:
			a = ''
			b = ''
			for j in i:
				a = a + (str(j[0]) + '_' + str(j[2]) + ',' + str(j[1])).ljust(12)
				b = b + (str(j[3][0]) + ' ' + str(j[3][1])).ljust(12)
			print(a)
			print(b)

def setnode(si):
	if si.parent == None:
		si.kid.Parent = si.parent
		return
	if si.kid != None:
		si.kid.Parent = si.parent
	if si.side == LEFT:
		si.parent.LeftKid = si.kid
	else:
		si.parent.RightKid = si.kid

def _del(node, root):
	si = search_extra(node, root)
	if si.kid != None:
		if si.kid.numkids() <= 1:
			if si.kid.LeftKid != None:
				setnode(searchinfo(si.kid.LeftKid, si.parent, si.side))
			elif si.kid.RightKid != None:
				setnode(searchinfo(si.kid.RightKid, si.parent, si.side))
			else:
				setnode(searchinfo(None, si.parent, si.side))
		else:
			swap_anddelete_last(si, search_prev(si.kid))

def swap_anddelete_last(si_A, si_B):
	si_A.kid.key = si_B.kid.key
	si_A.kid.value = si_B.kid.value
	_del(si_B)

def get_side(node):
	if node.Parent == None:
		return None
	if node.Parent.LeftKid == None:
		return RIGHT
	elif node.Parent.LeftKid.key == node.key:
		return LEFT
	else:
		return RIGHT

def sibling(node):
	p = node.Parent
	if p == None:
		return None
	if p.LeftKid == None or p.RightKid == None:
		return None
	if p.LeftKid.key == node.key:
		return node.Parent.RightKid
	else:
		return node.Parent.LeftKid

def uncle(node):
	if node.Parent == None:
		return None
	return sibling(node.Parent)

def tilt(x):
	y = x.Parent
	side = get_side(x)
	if side == LEFT:
		A = x.LeftKid
		B = x.RightKid
		C = y.RightKid
	else:
		A = y.LeftKid
		B = x.LeftKid
		C = x.RightKid

	def tilt_helper(x, y, B, side):
		if B != None:
			B.Parent = y
		x.Parent = y.Parent
		if side == LEFT:
			y.LeftKid = B
			x.RightKid = y
		else:
			y.RightKid = B
			x.LeftKid = y
		s2 = get_side(y)
		if s2 != None:
			if s2 == LEFT:
				y.Parent.LeftKid = x
			else:
				y.Parent.RightKid = x
		y.Parent = x
	Y_outer = None
	if side == LEFT:
		Y_outer = C
	else:
		Y_outer = A
	if x.flag == RED and y.flag == RED:
		tilt_helper(x, y, B, side)
	elif x.flag == RED and y.flag == BLACK and (B == None or B.flag == BLACK) and (Y_outer == None or Y_outer.flag == BLACK):
		tilt_helper(x, y, B, side)
		x.flag = BLACK
		y.flag = RED
	else:
		print('x')
		x.printNode()
		print('y')
		y.printNode()
		print('B')
		if B:
			B.printNode()
		print('Y_outer')
		if Y_outer:
			Y_outer.printNode()
		raise RuntimeError('I shouldnt be here')

def search_extra(node, root):
	if node.key == root.key:
		return searchinfo(root, root.Parent, None)
	if node.key < root.key:
		if root.LeftKid == None:
			return searchinfo(None, root, LEFT)
		else:
			return search_extra(node, root.LeftKid)
	elif root.RightKid == None:
		return searchinfo(None, root, RIGHT)
	else:
		return search_extra(node, root.RightKid)

def search_prev(node):
	n = node
	if node.LeftKid:
		n = n.LeftKid
		while n.RightKid:
			n = n.RightKid
	elif n.Parent and n.Parent.key < n.key:
		return n.Parent
	else:
		while n.Parent and n.Parent.key > n.key:
			n = n.Parent
		n = n.Parent
	if n and n.key == node.key:
		return None
	else:
		return n

def search_next(node):
	n = node
	if node.RightKid:
		n = n.RightKid
		while n.LeftKid:
			n = n.LeftKid
	elif n.Parent and n.Parent.key > n.key:
		return n.Parent
	else:
		while n.Parent and n.Parent.key < n.key:
			n = n.Parent
		n = n.Parent
	if n and n.key == node.key:
		return None
	else:
		return n

def BFS(root, NF=None, AF=None, AR=None):
	if root == None:
		return
	found = []
	next_nodes = []
	next_nodes.append(root)
	while next_nodes:
		n = next_nodes.pop(0)
		if NF != None:
			NF(n)
		if AF != None:
			AF(n, AR)
		found.append(n)
		if n.LeftKid != None:
			next_nodes.append(n.LeftKid)
		if n.RightKid != None:
			next_nodes.append(n.RightKid)
	return AR

def setlevel(node):
	if node.Parent == None:
		node.level = 0
	else:
		node.level = node.Parent.level + 1

def traverse(node, node_function, connector_function=None, order=IN_ORDER):
	if node == None:
		return node_function(None)
	if order == PRE_ORDER:
		x = node_function(node)
		a = traverse(node.LeftKid, node_function, connector_function, PRE_ORDER)
		b = traverse(node.RightKid, node_function, connector_function, PRE_ORDER)
	elif order == IN_ORDER:
		a = traverse(node.LeftKid, node_function, connector_function, IN_ORDER)
		x = node_function(node)
		b = traverse(node.RightKid, node_function, connector_function, IN_ORDER)
	elif order == POST_ORDER:
		a = traverse(node.LeftKid, node_function, connector_function, POST_ORDER)
		b = traverse(node.RightKid, node_function, connector_function, POST_ORDER)
		x = node_function(node)
	else:
		raise RuntimeError('I shouldnt be here')
	if connector_function != None:
		return connector_function(x, a, b)

def serialize_node_function(node):
	global FILEREADER
	if node != None:
		v = lambda node: str(node.value) if node.value != None else ''
		f = lambda node: str(node.flag) if node.flag != None else ''
		FILEREADER.write(str(node.key) + ',' + v(node) + ',' + f(node) + '\n')

def deserialize_reader_helper(nodestring):
	f = lambda x: None if x == '' else int(x)
	return tuple(map(f, nodestring.rstrip().split(',')))

def deserialize_helper(nodelist, cn, min_val, max_val):
	if len(nodelist) == 0:
		return
	n = nodelist[0]
	if (min_val == None or n.key > min_val) and (max_val == None or n.key < max_val):
		nodelist.pop(0)
		if cn.key == None:
			cn.set_as(n)
			n = cn
		if n.key < cn.key:
			cn.LeftKid = n
			n.Parent = cn
		elif n.key > cn.key:
			cn.RightKid = n
			n.Parent = cn
		deserialize_helper(nodelist, n, min_val, n.key)
		deserialize_helper(nodelist, n, n.key, max_val)

def accumulate_treestring(node, acc_result):
	if node.level != acc_result['level']:
		acc_result['level'] = node.level
		acc_result['levellist'].append([])
	lk = ''
	rk = ''
	if node.LeftKid != None:
		lk = '/'
	if node.RightKid != None:
		rk = '\\'
	acc_result['levellist'][acc_result['level']].append((node.key, node.value, lk + rk))

def accumulate_treestring2(node, acc_result):
	if node.level != acc_result['level']:
		acc_result['level'] = node.level
		acc_result['levellist'].append([])
	lk = ''
	rk = ''
	if node.LeftKid != None:
		lk = '/'
	if node.RightKid != None:
		rk = '\\'
	acc_result['levellist'][acc_result['level']].append((node.key, node.value, node.flag, (lk, rk)))
T = int(input())
for j in range(T):
	M = int(input())
	N = int(input())
	c = list(map(int, input().split()))
	t = BSTree(RedAndBlackTreeFunctions())
	for i in range(len(c)):
		t.insertOrAppend(c[i], i + 1)
	n = t.minNode()
	m = t.searchkey(M - n.key)
	while not m and n:
		n = search_next(n)
		m = t.searchkey(M - n.key)
	if m and n:
		k = n.value[0]
		kk = m.value[0]
		if n.key == m.key:
			kk = m.value[1]
		if k < kk:
			print(*(k, kk))
		else:
			print(*(kk, k))


__author__ = 'Saksham Chitkara'
test = int(input())
for t in range(0, test):
	money = int(input())
	flv_len = int(input())
	read = input().split()
	flavors = []
	for k in range(0, read.__len__()):
		flavors += [int(read[k])]
	for i in range(0, flv_len - 1):
		for j in range(i + 1, flv_len):
			if flavors[i] + flavors[j] == money:
				print(i + 1, j + 1)
				break
		else:
			continue
		break


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	M = int(sys.stdin.readline())
	N = int(sys.stdin.readline())
	C = list(map(int, sys.stdin.readline().split()))
	for (i, c) in enumerate(C[:-1]):
		for j in range(i + 1, len(C)):
			if C[j] == M - c:
				print(i + 1, j + 1)
				break


for _ in range(int(input())):
	m = int(input())
	l = int(input())
	things = input().split()
	done = 0
	for i in range(l - 1):
		for j in range(i + 1, l):
			if int(things[i]) + int(things[j]) == m:
				print(str(i + 1) + ' ' + str(j + 1))
				done = 1
				break
		if done == 1:
			break


t = int(input())
for i in range(t):
	money = int(input())
	flavors_count = int(input())
	flavors1 = input().split()
	flavors_cost = []
	for j in flavors1:
		flavors_cost.append(int(j))
	for (index, k) in enumerate(flavors_cost):
		found = 0
		for (index1, l) in enumerate(flavors_cost):
			if index != index1:
				if k + l == money:
					print(index + 1, index1 + 1)
					found = 1
					break
		if found == 1:
			break