The Chef's latest idea is that some cooks might work better in pairs. So, he is going to experiment by pairing up some of his employees to see if the quality of the food prepared in his kitchen increases. However, only some pairs of employees are compatible. Two employees that are not compatible cannot be paired together.

For each pair of compatible employees, the Chef has assigned a number estimating how well the overall quality of the food might increase. Of course, each employee can only be paired with at most one other employee. Furthermore, it is ok to not pair some employees. So, your goal is to help the Chef decide how to pair the employees to maximize the total amount that the overall quality of food increases.

------ Input ------ 

The first line contains a single integer denoting the number of test cases (at most 50). Each test case begins with two integers n and m. Here, n is the number of employees (between 2 and 1000) and m is the number of compatible pairs of employees (between 1 and 10,000). The employees are numbered from 0 to n-1. The next m lines describe a pair of compatible employees, one per line. The i'th such line contains two distinct integers u_{i},v_{i} between 0 and n-1. Strangely enough, the Chef estimates that picking the i'th pair u_{i},v_{i} will increase the quality of food prepared in his kitchen by exactly 2^{i}.

No pair of employees will be given more than once in the input. That is, for distinct indices i and j, we do not have both u_{i} = u_{j} and v_{i} = v_{j}, nor do we have both u_{i} = v_{j} and v_{i} = u_{j}.

------ Output ------ 

The output for each test case consists of the indices of the pairs of employees that are used in a maximum total value pairing (the indices are between 0 and m-1). These indices should be given in increasing order with a single space between consecutive numbers. If there is more than one possible output, then any will do.

----- Sample Input 1 ------ 
2
4 5
0 1
1 2
2 3
1 3
3 0
4 3
0 1
2 3
2 1
----- Sample Output 1 ------ 
1 4
2

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ind = []
	pair = []
	for i in range(m):
		x = list(map(int, input().split()))
		pair.append(x)
	test = [pair[m - 1][0], pair[m - 1][1]]
	ind.append(m - 1)
	for i in range(m - 2, -1, -1):
		if pair[i][0] not in test and pair[i][1] not in test:
			ind.append(i)
			test.append(pair[i][0])
			test.append(pair[i][1])
	ind.reverse()
	print(*ind)


T = int(input())
for i in range(T):
	(n, m) = list(map(int, input().split()))
	dict_pairs = {}
	for i in range(m):
		dict_pairs[i] = list(map(int, input().split()))
	list_eff = []
	list_ind = []
	for j in range(m - 1, -1, -1):
		if dict_pairs[j][0] not in list_eff and dict_pairs[j][1] not in list_eff:
			list_ind.append(j)
			list_eff.append(dict_pairs[j][0])
			list_eff.append(dict_pairs[j][1])
	list_ind.sort()
	out = str(list_ind[0])
	for l in range(1, len(list_ind)):
		out = out + ' ' + str(list_ind[l])
	print(out)


t = int(input())
for _ in range(t):
	(n, m) = (int(x) for x in input().split())
	a = {x for x in range(n)}
	s = []
	for i in range(m):
		s.append({int(x) for x in input().split()})
	result = []
	for (i, p) in reversed(list(enumerate(s))):
		if p.issubset(a):
			a -= p
			result.append(i)
	print(' '.join(map(str, sorted(result))))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	cpls = []
	vis = [0] * n
	res = []
	for i in range(m):
		(a, b) = map(int, input().split())
		cpls.append([a, b])
	for i in range(m - 1, -1, -1):
		a = cpls[i][0]
		b = cpls[i][1]
		if vis[a] == 0 and vis[b] == 0:
			vis[a] = 1
			vis[b] = 1
			res.append(i)
	print(*reversed(res))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	freq = []
	res = [0 for _ in range(m)]
	arr = []
	for _ in range(m):
		arr.append(list(map(int, input().split())))
	i = m - 1
	while i >= 0:
		if arr[i][0] not in freq and arr[i][1] not in freq:
			res[i] = 1
			freq += arr[i]
		i -= 1
	ans = [i for i in range(m) if res[i] == 1]
	print(*ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	chef = []
	uchef = []
	result = []
	for i in range(m):
		(a, b) = map(int, input().split())
		chef.append(a)
		chef.append(b)
	uchef.append(chef[-1])
	uchef.append(chef[-2])
	result.append(len(chef) // 2 - 1)
	for i in range(0, len(chef), 2):
		if chef[-1 - i] not in uchef and chef[-1 - i - 1] not in uchef and (chef[-1 - i - 1] != chef[-1 - i]):
			uchef.append(chef[-1 - i])
			uchef.append(chef[-1 - i - 1])
			result.append((len(chef) - i) // 2 - 1)
	result = sorted(result)
	for i in range(len(result)):
		if i == len(result) - 1:
			print(result[i])
		else:
			print(result[i], end=' ')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = []
	for i in range(m):
		(u, v) = map(int, input().split())
		li.append([u, v])
	a = []
	b = []
	for i in range(m - 1, -1, -1):
		if li[i][0] not in b and li[i][1] not in b:
			b.extend([li[i][0], li[i][1]])
			a += [i]
		if len(a) == n // 2:
			break
	print(*sorted(a))


def main():
	testCases = int(input())
	for _ in range(0, testCases):
		(numOfEmp, numOfComp) = [int(x) for x in input().split()]
		empArray = [0 for _ in range(0, numOfEmp)]
		pairArray = []
		resultArray = []
		for _ in range(0, numOfComp):
			pairArray.append([int(x) for x in input().split()])
		ind = len(pairArray) - 1
		while numOfEmp > 1 and ind >= 0:
			pair = pairArray[ind]
			if empArray[pair[0]] == 0 and empArray[pair[1]] == 0:
				empArray[pair[0]] = 1
				empArray[pair[1]] = 1
				resultArray.append(ind)
				numOfEmp = numOfEmp - 1
			ind = ind - 1
		while len(resultArray) > 1:
			print(resultArray.pop(), end=' ')
		print(resultArray.pop())
main()


for j in range(int(input())):
	x = []
	(n, m) = map(int, input().split())
	for i in range(m):
		y = list(map(int, input().split()))
		x.append(y)
	x.reverse()
	(a, b) = (x[0][0], x[0][1])
	aman = [a, b]
	z = [m - 1]
	for i in x:
		if i[0] not in aman and i[1] not in aman:
			aman.append(i[0])
			aman.append(i[1])
			z.append(m - x.index(i) - 1)
	z.reverse()
	print(*z)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = []
	flag = []
	l = []
	for i in range(m):
		l.append(list(map(int, input().split())))
	ans.append(m - 1)
	flag.append(l[m - 1][0])
	flag.append(l[m - 1][1])
	for i in range(1, m):
		if l[m - 1 - i][0] not in flag and l[m - 1 - i][1] not in flag:
			ans.append(m - 1 - i)
			flag.append(l[m - 1 - i][0])
			flag.append(l[m - 1 - i][1])
	ans = sorted(ans)
	print(*ans)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = [0] * n
	l = []
	x = []
	for i in range(m):
		l.append(list(map(int, input().split())))
	for i in range(m - 1, -1, -1):
		if a[l[i][0]] == 0 and a[l[i][1]] == 0:
			a[l[i][0]] = 1
			a[l[i][1]] = 1
			x.append(i)
	x.reverse()
	print(*x)
	t -= 1


for t in range(int(input())):
	(n, m) = map(int, input().split())
	pairs = []
	status = [0] * n
	selected = []
	for i in range(m):
		pairs.append(list(map(int, input().split())))
	i = m - 1
	while 0 in status and i >= 0:
		if status[pairs[i][0]] == 0 and status[pairs[i][1]] == 0:
			selected = [i] + selected[:]
			status[pairs[i][0]] = 1
			status[pairs[i][1]] = 1
		i -= 1
	print(*selected)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	pairs = []
	check = [0] * n
	ans = []
	for _ in range(m):
		(a, b) = map(int, input().split())
		pairs.append([a, b])
	i = m
	for x in pairs[::-1]:
		i -= 1
		if check[x[0]] == check[x[1]] == 0:
			(check[x[0]], check[x[1]]) = (1, 1)
			ans.append(i)
	print(*sorted(ans))


for _ in range(int(input())):
	l = []
	(m, n) = map(int, input().split())
	for _ in range(n):
		(a, b) = map(int, input().split())
		l.append((a, b))
	l = l[::-1]
	(k, s) = ([], [])
	for i in range(n):
		if l[i][0] in k or l[i][1] in k:
			pass
		else:
			k.append(l[i][0])
			k.append(l[i][1])
			s.append(n - 1 - i)
	s.sort()
	print(*s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(m):
		a.append(list(map(int, input().split())))
	emp = []
	p = []
	for i in range(m - 1, -1, -1):
		if a[i][0] not in emp and a[i][1] not in emp:
			emp.append(a[i][0])
			emp.append(a[i][1])
			p.append(i)
	print(*sorted(p))


try:
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = [0] * n
		l = []
		x = []
		for i in range(m):
			l.append(list(map(int, input().split())))
		for i in range(m - 1, -1, -1):
			if a[l[i][0]] == 0 and a[l[i][1]] == 0:
				a[l[i][0]] = 1
				a[l[i][1]] = 1
				x.append(i)
		x.reverse()
		print(*x)
except:
	pass


t = int(input())
for ni in range(t):
	(n, m) = map(int, input().split())
	l = []
	for nj in range(m):
		(a, b) = map(int, input().split())
		l.append([a, b])
	l1 = list()
	place = list()
	for i in range(m - 1, -1, -1):
		if l[i][0] not in l1 and l[i][1] not in l1:
			l1.append(l[i][0])
			l1.append(l[i][1])
			place.append(i)
	print(*sorted(place))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for x in range(m):
		arr.append(list(map(int, input().split())))
	s = []
	a = []
	for i in range(m - 1, -1, -1):
		if arr[i][0] not in s and arr[i][1] not in s:
			s.append(arr[i][0])
			s.append(arr[i][1])
			a.append(i)
	a.sort()
	print(*a)


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	array = []
	used = [0] * N
	indices = []
	for i in range(M):
		(u, v) = map(int, input().split())
		array.append([u, v])
	for i in range(M - 1, -1, -1):
		a = array[i][0]
		b = array[i][1]
		if used[a] + used[b] == 0:
			indices.append(i)
			used[a] = 1
			used[b] = 1
	indices = indices[-1::-1]
	print(*indices)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	li = []
	added = []
	ct = []
	for _ in range(m):
		(x, y) = map(int, input().split())
		li.append([x, y])
	l = len(li)
	i = 1
	while len(added) < n and i <= m:
		if li[-i][0] not in added and li[-i][1] not in added:
			added += li[-i]
			ct += [l - i]
		i += 1
	ct.sort()
	print(*ct)


t = int(input())
for val in range(0, t):
	(n, m) = map(int, input().split())
	l1 = []
	for va in range(0, m):
		(x, y) = map(int, input().split())
		l1.append(x)
		l1.append(y)
	l2 = []
	l3 = []
	l2.append(l1[len(l1) - 1])
	l2.append(l1[len(l1) - 2])
	l3.append(m - 1)
	s = m - 1
	for vb in range(len(l1) - 3, -2, -2):
		s = s - 1
		if l1[vb] not in l2 and l1[vb - 1] not in l2:
			l3.append(s)
			l2.append(l1[vb])
			l2.append(l1[vb - 1])
	l3.reverse()
	print(*l3)


for case in range(int(input())):
	(n, m) = map(int, input().split())
	pair = []
	chef = [False] * n
	for i in range(m):
		(u, v) = map(int, input().split())
		pair.append([u, v])
	final = []
	for i in range(m - 1, -1, -1):
		if not chef[pair[i][0]] and (not chef[pair[i][1]]):
			chef[pair[i][0]] = chef[pair[i][1]] = True
			final.insert(0, i)
	print(*final)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst = []
	for _ in range(m):
		lst.append(list(map(int, input().split())))
	sel = []
	ans = []
	for i in range(m - 1, -1, -1):
		if lst[i][0] not in sel and lst[i][1] not in sel:
			sel.append(lst[i][0])
			sel.append(lst[i][1])
			ans.append(i)
	ans.sort()
	print(*ans)


tests = int(input())
for i in range(tests):
	(n, m) = map(int, input().split())
	arr = []
	for j in range(m):
		arr.append(list(map(int, input().split())))
	selected = []
	ans = []
	for j in range(len(arr) - 1, -1, -1):
		if arr[j][0] not in selected and arr[j][1] not in selected:
			selected.append(arr[j][0])
			selected.append(arr[j][1])
			ans.append(j)
	ans.sort()
	print(*ans)


t = int(input())
for count in range(t):
	(num_emps, num_pairs) = [int(x) for x in input().split(' ')]
	pairs = []
	used_pairs = []
	used_emps = set()
	for p in range(num_pairs):
		(e1, e2) = [int(x) for x in input().split(' ')]
		pairs.append((p, e1, e2))
	for (p, e1, e2) in pairs[::-1]:
		if e1 not in used_emps and e2 not in used_emps:
			used_pairs.append(p)
			used_emps.add(e1)
			used_emps.add(e2)
	print(' '.join((str(i) for i in used_pairs[::-1])))


t = int(input())
for i in range(0, t):
	(n, m) = input().strip().split()
	n = int(n)
	m = int(m)
	b = []
	a = []
	d = []
	for j in range(0, m):
		e = list(map(int, input().strip().split()))
		b.append(e)
	d.append(m - 1)
	a.append(b[m - 1][0])
	a.append(b[m - 1][1])
	for k in range(m - 2, -1, -1):
		if b[k][0] in a:
			z = 0
		elif b[k][1] in a:
			z = 0
		else:
			d.append(k)
			a.append(b[k][0])
			a.append(b[k][1])
	print(*d[::-1], sep=' ')


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(m):
		a.append(list(map(int, input().split())))
	emp = []
	pairindex = []
	for i in range(m - 1, -1, -1):
		if a[i][0] not in emp and a[i][1] not in emp:
			emp.append(a[i][0])
			emp.append(a[i][1])
			pairindex.append(i)
	print(*sorted(pairindex))


tes = int(input())
for g in range(tes):
	(n, m) = map(int, input().split())
	a = [[-1 for j in range(2)] for i in range(m)]
	for i in range(m):
		(a[i][0], a[i][1]) = map(int, input().split())
	emplis = []
	ans = []
	for i in range(n):
		emplis.append(i)
	track = len(a) - 1
	while track >= 0:
		if a[track][0] in emplis and a[track][1] in emplis:
			emplis.remove(a[track][0])
			emplis.remove(a[track][1])
			ans.append(track)
			track -= 1
		else:
			track -= 1
	ans = sorted(ans)
	print(' '.join(map(str, ans)))


for _ in range(int(input())):
	(employees, pairs) = map(int, input().split())
	matches = []
	for __ in range(pairs):
		matches.append(tuple(map(int, input().split())))
	matches = matches[::-1]
	A = []
	used = set()
	for (i, m) in enumerate(matches):
		if len(set(m) & used) == 0:
			A.append(pairs - i - 1)
			used |= set(m)
	A.sort()
	print(*A)


t = int(input())
for I in range(t):
	(n, m) = [int(i) for i in input().split()]
	ind = []
	ha_sh = [0] * n
	a = []
	for i in range(m):
		b = [int(i) for i in input().split()]
		a.append(b)
	for i in range(len(a) - 1, -1, -1):
		if ha_sh[a[i][0]] == 0 and ha_sh[a[i][1]] == 0:
			ind.append(i)
			ha_sh[a[i][0]] = 1
			ha_sh[a[i][1]] = 1
	ind.sort()
	print(*ind)


from collections import deque
t = int(input())
for _ in range(t):
	(n, m) = [int(a) for a in input().strip().split()]
	N = [True] * n
	M = deque([])
	for i in range(m):
		(u, v) = [int(a) for a in input().strip().split()]
		M.append((u, v))
	list = []
	while m != 0:
		(u, v) = M.pop()
		if N[u] and N[v]:
			N[u] = False
			N[v] = False
			list.append(m - 1)
		m -= 1
	print(' '.join(map(str, reversed(list))))