This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.

You are given an array $[a_1, a_2, \ldots a_n]$ consisting of integers $-1$ and $1$. You have to build a partition of this array into the set of segments $[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$ with the following property:

Denote the alternating sum of all elements of the $i$-th segment as $s_i$: $s_i$ = $a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + \ldots \pm a_{r_i}$. For example, the alternating sum of elements of segment $[2, 4]$ in array $[1, 0, -1, 1, 1]$ equals to $0 - (-1) + 1 = 2$.

The sum of $s_i$ over all segments of partition should be equal to zero.

Note that each $s_i$ does not have to be equal to zero, this property is about sum of $s_i$ over all segments of partition.

The set of segments $[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$ is called a partition of the array $a$ of length $n$ if $1 = l_1 \le r_1, l_2 \le r_2, \ldots, l_k \le r_k = n$ and $r_i + 1 = l_{i+1}$ for all $i = 1, 2, \ldots k-1$. In other words, each element of the array must belong to exactly one segment.

You have to build a partition of the given array with properties described above or determine that such partition does not exist.

Note that it is not required to minimize the number of segments in the partition.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10000$). Description of the test cases follows.

The first line of each test case contains an integer $n$ ($1 \le n \le 200000$) — the length of the array $a$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($a_i$ is $-1$ or $1$) — the elements of the given array.

It's guaranteed that the sum of $n$ over all test cases does not exceed $200000$.


-----Output-----

For each test case, if required partition does not exist, print $-1$. Otherwise, print an integer $k$ — the number of segments in the partition.

Then in the $i$-th of the following $k$ lines print two integers $l_i$ and $r_i$ — description of the $i$-th segment. The following conditions should be satisfied:

$l_i \le r_i$ for each $i$ from $1$ to $k$.

$l_{i + 1} = r_i + 1$ for each $i$ from $1$ to $(k - 1)$.

$l_1 = 1, r_k = n$.

If there are multiple correct partitions of the array, print any of them.


-----Examples-----

Input
4
4
1 1 1 1
6
-1 1 1 1 1 1
3
1 -1 1
1
1
Output
1
1 4
2
1 3
4 6
-1
-1


-----Note-----

In the first test case we can build a partition of one segment of length $4$. The sum of this segment will be equal to $1 - 1 + 1 - 1 = 0$.

In the second test case we can build a partition of two segments of length $3$. The sum of the first segment will be equal to $-1 -1 + 1 = -1$, and the sum of the second segment: $1 - 1 + 1 = 1$. So, the total sum will be equal to $-1 + 1 = 0$.

In the third and in the fourth test cases it can be proved that there are no required partition.

Difficulty: EASY
Tags: Greedy algorithms

Dynamic programming

Constructive algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
import sys

def solve():
	inp = sys.stdin.readline
	n = int(inp())
	a = list(map(int, inp().split()))
	if len(a) % 2 == 1:
		print(-1)
	else:
		s = []
		for i in range(0, n, 2):
			if a[i] != a[i + 1]:
				s.append(f'{i + 1} {i + 1}')
				s.append(f'{i + 2} {i + 2}')
			else:
				s.append(f'{i + 1} {i + 2}')
		print(len(s))
		print('\n'.join(s))

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


def get_pair(data, length):
	if length % 2 != 0:
		print(-1)
		return
	else:
		count = 0
		arr = []
		raw = ''
		for i in range(0, length, 2):
			if data[i] == data[i + 1]:
				count += 1
				raw = raw + f'\n{i + 1} {i + 2}'
			else:
				count += 2
				raw = raw + f'\n{i + 1} {i + 1}\n{i + 2} {i + 2}'
	print(count, end='')
	print(raw)

def main():
	n = int(input())
	for i in range(n):
		length = int(input())
		data = list(map(int, input().split()))
		get_pair(data, length)
main()


def partition(lst, l):
	n = 0
	seg = []
	for i in range(0, l, 2):
		if lst[i] == lst[i + 1]:
			n += 1
			seg.append((i + 1, i + 2))
		else:
			n += 2
			seg.append((i + 1, i + 1))
			seg.append((i + 2, i + 2))
	print(n)
	for t in seg:
		print('%d %d' % t)
n_cases = int(input())
cases = []
for i in range(n_cases):
	n = int(input())
	lst = [int(x) for x in input().split()]
	cases.append(lst)
for lst in cases:
	l = len(lst)
	if l % 2 == 1:
		print(-1)
	else:
		partition(lst, l)


MOD = int(2000000.0)
for _ in range(int(input())):
	n = int(input())
	n %= MOD
	array = list(map(int, input().split()))
	if n & 1:
		print(-1)
	else:
		counter = 0
		for i in range(0, n - 1, 2):
			counter += 1 + int(array[i] * array[i + 1] == -1)
		print(counter)
		for i in range(0, n - 1, 2):
			if array[i] * array[i + 1] == -1:
				print(f'{i + 1} {i + 1}')
				print(f'{i + 2} {i + 2}')
			else:
				print(f'{i + 1} {i + 2}')


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 1:
		print(-1)
	else:
		c = 0
		d = []
		for i in range(0, n - 1, 2):
			if a[i] == a[i + 1]:
				c += 1
				d.append(str(i + 1) + ' ' + str(i + 2))
			else:
				c += 2
				d.append(str(i + 1) + ' ' + str(i + 1))
				d.append(str(i + 2) + ' ' + str(i + 2))
		print(c)
		for i in range(len(d)):
			print(d[i])


def solve(arr):
	if len(arr) % 2 == 1:
		return False
	if arr[0] * arr[1] < 0:
		splits = [(0, 0), (1, 1)]
	else:
		splits = [(0, 1)]
	for i in range(2, len(arr) - 1, 2):
		j = i // 2
		if arr[i] * arr[i + 1] < 0:
			splits.append((i, i))
			splits.append((i + 1, i + 1))
		else:
			splits.append((i, i + 1))
	return splits
t = int(input())
for tt in range(t):
	input()
	arr = input().split(' ')
	arr = [int(el) for el in arr]
	splits = solve(arr)
	if not splits:
		print('-1')
		continue
	print(len(splits))
	for split in splits:
		print(f'{split[0] + 1} {split[1] + 1}')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	if n % 2:
		print(-1)
		continue
	c = 0
	f = []
	for k in range(0, n, 2):
		c += 1
		if l[k] == l[k + 1]:
			f.append(str(k + 1) + ' ' + str(k + 2))
		else:
			c += 1
			f.append(str(k + 1) + ' ' + str(k + 1))
			f.append(str(k + 2) + ' ' + str(k + 2))
	print(c)
	for k in f:
		print(k)


for _ in range(int(input())):
	n = int(input())
	l = [int(ele) for ele in input().split()]
	if n % 2 == 1:
		print(-1)
	else:
		s = []
		i = 1
		while i < n:
			if l[i] == l[i - 1]:
				z = str(i) + ' ' + str(i + 1)
				s.append(z)
				i += 2
			else:
				z = str(i) + ' ' + str(i)
				s.append(z)
				z = str(i + 1) + ' ' + str(i + 1)
				s.append(z)
				i += 2
		print(len(s))
		for e in s:
			print(e)


test_cases = int(input())
for x in range(test_cases):
	length = int(input())
	arr = list(map(int, input().split()))
	if length % 2 == 1:
		print(-1)
	else:
		l = [0]
		for i in range(0, length, 2):
			if arr[i] == arr[i + 1]:
				l.append(i + 2)
			else:
				l.append(i + 1)
				l.append(i + 2)
		print(len(l) - 1)
		for i in range(len(l) - 1):
			print(str(l[i] + 1) + ' ' + str(l[i + 1]))


def m_sum(arr):
	if len(arr) == 0:
		return 0
	if len(arr) == 1:
		return arr[0]
	for index in range(len(arr)):
		if index % 2 == 1:
			arr[index] = -1 * arr[index]
	return sum(arr)

def fun(arr):
	if len(arr) % 2 == 1:
		print(-1)
		return
	cnt = 0
	for i in range(0, len(arr), 2):
		if arr[i + 1] == arr[i]:
			cnt += 1
		else:
			cnt += 2
	print(cnt)
	for i in range(0, len(arr), 2):
		if arr[i + 1] == arr[i]:
			print(i + 1, i + 2)
		else:
			print(i + 1, i + 1)
			print(i + 2, i + 2)

def algorithm(mass):
	for val in mass:
		fun(val)

def parsing():
	n = int(input())
	res = []
	while n > 0:
		k = int(input())
		val = input()
		res.append(list(map(int, val.split(' '))))
		n -= 1
	return res
res = parsing()
algorithm(res)


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(a, n):
	if n % 2 == 1:
		return []
	ans = []
	for i in range(0, n, 2):
		if a[i] == a[i + 1]:
			ans.append([i + 1, i + 2])
		else:
			ans.append([i + 1, i + 1])
			ans.append([i + 2, i + 2])
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = solve(a, n)
	if len(res) == 0:
		print(-1)
	else:
		print(len(res))
		for (l, r) in res:
			print('{} {}'.format(l, r))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 1:
		print(-1)
	else:
		b = []
		for i in range(0, len(a), 2):
			if a[i] == a[i + 1]:
				b += [i + 1, i + 2]
			else:
				b += [i + 1, i + 1, i + 2, i + 2]
		print(len(b) // 2)
		for i in range(0, len(b), 2):
			print(b[i], b[i + 1])


t = int(input())
for i in range(t):
	n = int(input())
	breaks = [-1]
	nums = [int(i) for i in input().split()]
	if len(nums) % 2 == 1:
		print(-1)
	else:
		for j in range(0, len(nums), 2):
			if nums[j] == nums[j + 1]:
				breaks.append(j + 1)
			else:
				breaks.append(j)
				breaks.append(j + 1)
		print(len(breaks) - 1)
		for j in range(len(breaks) - 1):
			print(breaks[j] + 2, breaks[j + 1] + 1)


def solve(A):
	if len(A) % 2:
		return -1
	splits = [1]
	for (i, (first, second)) in enumerate(zip(A[::2], A[1::2])):
		if first != second:
			splits.append(2 * i + 1)
			splits.append(2 * i + 2)
		splits.append(2 * i + 2)
		splits.append(2 * i + 3)
	return splits[:-1]

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

def print_array(A):
	if isinstance(A, int):
		print(A)
	else:
		print(len(A) // 2)
		for (start, end) in zip(A[::2], A[1::2]):
			print(start, end)
num_tests = int(input())
for _ in range(num_tests):
	_len = int(input())
	arr = read_int_list()
	sol = solve(arr)
	print_array(sol)


t = int(input())
for i in range(t):
	n = int(input())
	arr = input().split()
	arr = [int(x) for x in arr]
	if n % 2:
		print('-1')
	else:
		ans = []
		noa = 0
		for j in range(0, n, 2):
			if arr[j] == arr[j + 1]:
				noa += 1
			else:
				noa += 2
		print(noa)
		for j in range(0, n, 2):
			if arr[j] == arr[j + 1]:
				print(j + 1, j + 2)
			else:
				print(j + 1, j + 1)
				print(j + 2, j + 2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 1:
		print(-1)
		continue
	ans = []
	for i in range(0, n // 2):
		if a[i * 2] != a[i * 2 + 1]:
			ans.append((i * 2 + 1, i * 2 + 1))
			ans.append((i * 2 + 2, i * 2 + 2))
		else:
			ans.append((i * 2 + 1, i * 2 + 2))
	print(len(ans))
	for i in ans:
		print(i[0], i[1])


import math

def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	soln = []
	if n % 2 == 1:
		print(-1)
	else:
		for i in range(0, n, 2):
			if arr[i] == arr[i + 1]:
				soln.append([i + 1, i + 2])
			else:
				soln.append([i + 1, i + 1])
				soln.append([i + 2, i + 2])
		print(len(soln))
		for s in soln:
			print(s[0], s[1])
t = int(input())
while t:
	t -= 1
	solve()


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n % 2:
		print(-1)
	else:
		i = 0
		ans = []
		while i < n:
			if arr[i] == arr[i + 1]:
				ans.append((i + 1, i + 2))
			else:
				ans.append((i + 1, i + 1))
				ans.append((i + 2, i + 2))
			i += 2
		print(len(ans))
		for i in ans:
			print(*i)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = []
	idx = 0
	while idx < n:
		if idx + 1 == n:
			res = []
			break
		if arr[idx] == arr[idx + 1]:
			res.append((idx + 1, idx + 2))
		else:
			res.append((idx + 1, idx + 1))
			res.append((idx + 2, idx + 2))
		idx += 2
	if not res:
		print(-1)
	else:
		print(len(res))
		for e in res:
			print(*e)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n % 2 == 1:
		print(-1)
	else:
		l1 = []
		for i in range(0, n, 2):
			if l[i] == l[i + 1]:
				l1.append((i + 1, i + 2))
			else:
				l1.append((i + 1, i + 1))
				l1.append((i + 2, i + 2))
		print(len(l1))
		for i in l1:
			print(*i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] + [int(x) for x in input().split()]
	l = []
	r = []
	if n % 2 != 0:
		print(-1)
		continue
	for i in range(1, n + 1, 2):
		if a[i] == a[i + 1]:
			l.append(i)
			r.append(i + 1)
		else:
			l.append(i)
			r.append(i)
			l.append(i + 1)
			r.append(i + 1)
	print(len(l))
	for i in range(len(l)):
		print(l[i], r[i])


t = int(input())
for _ in range(t):
	length = int(input())
	arr = [int(x) for x in input().split()]
	if length % 2 == 1:
		print(-1)
	else:
		ans = []
		i = 0
		while i < length - 1:
			if arr[i] == arr[i + 1]:
				ans.append([i + 1, i + 2])
				i += 2
			else:
				ans.append([i + 1, i + 1])
				ans.append([i + 2, i + 2])
				i += 2
		if len(ans) != 0:
			print(len(ans))
			for x in ans:
				print(str(x[0]) + ' ' + str(x[1]))


t = int(input())
for i in range(0, t):
	l = int(input())
	arr = list(map(int, input().split(' ')))
	if sum(arr) % 2 == 1:
		print(-1)
		continue
	if l % 2 == 1:
		print(-1)
		continue
	c = 0
	for e in range(0, l, 2):
		if arr[e] == arr[e + 1]:
			c = c + 1
		else:
			c = c + 2
	print(c)
	for e in range(0, l, 2):
		if arr[e] == arr[e + 1]:
			print(e + 1, end=' ')
			print(e + 2)
			c = c + 1
		else:
			print(e + 1, end=' ')
			print(e + 1)
			print(e + 2, end=' ')
			print(e + 2)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if n % 2 != 0:
		print(-1)
	else:
		res = []
		for i in range(0, n, 2):
			if lis[i] == lis[i + 1]:
				res.append([i + 1, i + 2])
			else:
				res.append([i + 1, i + 1])
				res.append([i + 2, i + 2])
		print(len(res))
		for (x, y) in res:
			print(x, y)


for i in range(int(input())):
	g = int(input())
	a = list(map(int, input().split()))
	if g % 2 == 1:
		print(-1)
		continue
	res = []
	for i in range(0, g // 2):
		if a[2 * i] - a[2 * i + 1] == 0:
			res.append([2 * i + 1, 2 * i + 2])
		else:
			res.append([2 * i + 1, 2 * i + 1])
			res.append([2 * i + 2, 2 * i + 2])
	print(len(res))
	for j in res:
		print(*j)


def zeros(L):
	L2 = []
	i = 0
	if len(L) % 2 != 0:
		print(-1)
		return
	while i < len(L) - 1:
		if L[i] == L[i + 1]:
			L2.append(i + 1)
			L2.append(i + 2)
			i += 2
		else:
			L2.append(i + 1)
			L2.append(i + 1)
			L2.append(i + 2)
			L2.append(i + 2)
			i += 2
	print(int(len(L2) / 2))
	for i in range(0, len(L2) - 1, 2):
		print(L2[i], end=' ')
		print(L2[i + 1])
	return
x = int(input())
for i in range(x):
	length = int(input())
	L = [int(x) for x in input().split()]
	zeros(L)


def nonz(L):
	if len(L) % 2 != 0:
		print(-1)
		return 0
	i = 0
	ans = []
	while i < len(L) - 1:
		if L[i] == L[i + 1]:
			ans.append(i + 1)
			ans.append(i + 2)
			i += 2
		else:
			ans.append(i + 1)
			ans.append(i + 1)
			ans.append(i + 2)
			ans.append(i + 2)
			i += 2
	print(int(len(ans) / 2))
	for i in range(0, len(ans) - 1, 2):
		print(ans[i], end=' ')
		print(ans[i + 1])
	return 0
x = int(input())
for i in range(x):
	leng = int(input())
	s = input()
	L = [int(n) for n in s.split()]
	nonz(L)


t = int(input())
for z in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	l = []
	if n % 2 == 1:
		print(-1)
	else:
		for i in range(0, n - 1, 2):
			if a[i] == a[i + 1]:
				l.append(i + 1)
				l.append(i + 2)
			else:
				l.append(i + 1)
				l.append(i + 1)
				l.append(i + 2)
				l.append(i + 2)
		print(len(l) // 2)
		for j in range(0, len(l) - 1, 2):
			print(l[j], l[j + 1])


N = int(input())
for k in range(N):
	(n, _array) = (int(input()), input())
	array = [int(i) for i in _array.split(' ')]
	if n % 2 == 1:
		print(-1)
	else:
		segs = []
		for i in range(0, len(array), 2):
			if array[i] == array[i + 1]:
				segs += [i + 1, i + 2]
			else:
				segs += [i + 1, i + 1, i + 2, i + 2]
		print(len(segs) // 2)
		for j in range(0, len(segs), 2):
			print(segs[j], segs[j + 1])


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in a:
		s += i
	if s & 1:
		print(-1)
	else:
		ans = []
		c1 = 0
		for i in range(1, n + 1, 2):
			if a[i] == a[i - 1]:
				ans.append([i, i + 1])
				c1 += 1
			else:
				ans.append([i, i])
				ans.append([i + 1, i + 1])
				c1 += 2
		print(c1)
		for i in ans:
			print(*i)


t = int(input())
for x in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	if n % 2 != 0:
		print(-1)
	else:
		answer = []
		for i in range(n // 2):
			if array[2 * i] - array[2 * i + 1] == 0:
				answer.append((2 * i + 1, 2 * i + 2))
			else:
				answer.append((2 * i + 1, 2 * i + 1))
				answer.append((2 * i + 2, 2 * i + 2))
		print(len(answer))
		for j in answer:
			print(j[0], j[1])


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	flag = 0
	if n % 2 == 1:
		print('-1')
	else:
		for j in range(n - 1):
			if a[j] == a[j + 1] and flag == 0:
				flag = 1
				ans.append([j + 1, j + 2])
				continue
			elif flag == 0:
				flag = 1
				ans.append([j + 1])
				ans.append([j + 2])
				continue
			flag = 0
	if len(ans) != 0:
		print(len(ans))
		for i in ans:
			if len(i) == 1:
				print(i[0], i[0])
			else:
				print(' '.join(map(str, i)))


t = int(input())
for _ in range(t):
	n = int(input())
	ar = [int(i) for i in input().split()]
	if n % 2 == 1:
		print(-1)
	else:
		ans = []
		ct = 0
		for i in range(0, n, 2):
			if ar[i] == ar[i + 1]:
				ans.append([i + 1, i + 2])
				ct += 1
			else:
				ans.append([i + 1, i + 1])
				ans.append([i + 2, i + 2])
				ct += 2
		print(ct)
		for a in ans:
			print(a[0], a[1])


for s in [*open(0)][2::2]:
	l = [*map(int, s.split())]
	n = len(l)
	S = sum((l[i] * (2 * (i & 1) - 1) for i in range(n)))
	if S & 1:
		print(-1)
	else:
		A = []
		for i in range(0, n, 2):
			if l[i] == l[i + 1]:
				A += [(i + 1, i + 2)]
			else:
				A += [(i + 1, i + 1)]
				A += [(i + 2, i + 2)]
		print(len(A))
		for x in A:
			print(*x)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 1:
		print(-1)
		continue
	b = []
	for j in range(0, n, 2):
		if a[j] == a[j + 1]:
			b.append([j + 1, j + 2])
		else:
			b.append([j + 1, j + 1])
			b.append([j + 2, j + 2])
	print(len(b))
	for j in b:
		print(j[0], j[1])


import math
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())
for _ in range(int(input())):
	n = inp()
	arr = inlt()
	if n % 2 == 1:
		print(-1)
	else:
		ans = []
		for i in range(0, n, 2):
			if arr[i] == arr[i + 1]:
				ans.append([i + 1, i + 2])
			else:
				ans.append([i + 1, i + 1])
				ans.append([i + 2, i + 2])
		print(len(ans))
		for i in ans:
			print(*i)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	i = 0
	if n % 2 != 0:
		print(-1)
		continue
	while i < len(a):
		if a[i] == a[i + 1]:
			l.append([i + 1, i + 2])
		else:
			l.append([i + 1, i + 1])
			l.append([i + 2, i + 2])
		i += 2
	else:
		print(len(l))
		for i in range(len(l)):
			print(*l[i])


def N():
	return int(input())

def A():
	return [int(x) for x in input().split()]

def S():
	return input()
for _ in range(N()):
	n = N()
	if 'er9fj48gh48gh4' == 14194665565:
		print('Tanmay')
	a = A()
	if n % 2 == 1:
		print(-1)
		continue
	ans = []
	for i in range(0, n, 2):
		if a[i] == a[i + 1]:
			ans.append([i + 1, i + 2])
			continue
		ans.append([i + 1, i + 1])
		ans.append([i + 2, i + 2])
	print(len(ans))
	for i in ans:
		print(i[0], i[1])


import math
t = int(input())
for tc in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 1:
		print(-1)
		continue
	else:
		i = 0
		ans = []
		while i < n:
			if a[i + 1] * a[i] > 0:
				ans.append((i + 1, i + 2))
			else:
				ans.append((i + 1, i + 1))
				ans.append((i + 2, i + 2))
			i += 2
		print(len(ans))
		for i in range(len(ans)):
			print(*ans[i])


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if sum(a) % 2 == 1:
		print(-1)
	else:
		nonz = []
		for j in range(0, n - 1, 2):
			if a[j] == a[j + 1]:
				nonz.append(list(range(j + 1, j + 3)))
			else:
				nonz.append(list(range(j + 1, j + 2)))
				nonz.append(list(range(j + 2, j + 3)))
		print(len(nonz))
		for k in nonz:
			print(k[0], k[-1])


T = int(input())

def sgn(x):
	if x > 0:
		return 1
	if x < 0:
		return -1
	if x == 0:
		return 0
while T > 0:
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 != 0:
		print(-1)
		T = T - 1
		continue
	i = 0
	part = []
	while i < n / 2:
		if sgn(a[2 * i]) == sgn(a[2 * i + 1]):
			part.append(2 * i + 1)
		else:
			part.extend([2 * i + 1, 2 * i + 2])
		i = i + 1
	print(len(part))
	for k in range(len(part)):
		if k == 0:
			print(part[k], end=' ')
		else:
			print(part[k] - 1)
			print(part[k], end=' ')
	print(n)
	T = T - 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n % 2:
		print(-1)
	else:
		res = []
		i = 0
		k = 0
		while i < n - 1:
			if arr[i] == arr[i + 1]:
				k += 1
				res.append([i + 1, i + 2])
				i += 2
			else:
				k += 2
				res.append([i + 1, i + 1])
				res.append([i + 2, i + 2])
				i += 2
		print(k)
		for i in range(k):
			print(*res[i])


def ways(arr, n):
	if n % 2 != 0:
		print(-1)
	else:
		res = []
		i = 0
		while i < n:
			if arr[i] == arr[i + 1]:
				res.append([i + 1, i + 2])
			else:
				res.append([i + 1, i + 1])
				res.append([i + 2, i + 2])
			i += 2
		print(len(res))
		for i in range(len(res)):
			print(int(res[i][0]), int(res[i][1]))
tem = int(input())
for i in range(tem):
	n = int(input())
	l = input().split()
	arr = []
	for i in range(n):
		arr.append(int(l[i]))
	ways(arr, n)


def sign(i):
	if i > 0:
		return 1
	elif i < 0:
		return -1
	else:
		return 0
for _ in range(int(input())):
	l = int(input())
	v = list(map(lambda x: int(x), input().split(' ')))
	if l & 1:
		print(-1)
		continue
	res = []
	j = 0
	for i in range(0, l, 2):
		if sign(v[i]) == sign(v[i + 1]):
			res += [(i + 1, i + 2)]
		else:
			res += [(i + 1, i + 1)]
			res += [(i + 2, i + 2)]
	print(len(res))
	for seg in res:
		print(str(seg[0]), str(seg[1]))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	if n == 1:
		print(-1)
	else:
		ans = 0
		seg = []
		while i < n - 1:
			if l[i] == l[i + 1]:
				seg.append([i + 1, i + 2])
				ans += l[i] - l[i + 1]
				i += 2
			else:
				ans += l[i]
				seg.append([i + 1, i + 1])
				i += 1
				ans += l[i]
				seg.append([i + 1, i + 1])
				i += 1
		if i == n - 1:
			seg.append([n, n])
			ans += l[-1]
		if ans == 0:
			print(len(seg))
			for (i, j) in seg:
				print(i, j)
		else:
			print(-1)


import sys
input = sys.stdin.readline
k = int(input())
for l in range(k):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = 0
	if n % 2 == 1:
		print(-1)
		continue
	else:
		for i in range(0, n, 2):
			if arr[i + 1] == arr[i]:
				cnt += 1
			else:
				cnt += 2
		print(cnt)
		for i in range(0, n, 2):
			if arr[i + 1] == arr[i]:
				print(i + 1, ' ', i + 2)
			else:
				print(i + 1, ' ', i + 1)
				print(i + 2, ' ', i + 2)


for i in range(int(input())):
	nos = int(input())
	series = []
	for i in input().split(' '):
		series.append(int(i))
	if nos % 2 == 0:
		answer = []
		for tally in range(nos):
			if (tally + 1) % 2 == 0:
				if series[tally - 1] - series[tally] == 0:
					answer.append((tally, tally + 1))
				else:
					answer.append((tally, tally))
					answer.append((tally + 1, tally + 1))
		print(len(answer))
		for q in answer:
			print(str(q[0]), str(q[1]))
	else:
		print(-1)


def non_zerosum(n, l):
	i = 0
	res = []
	if n % 2 == 1:
		return -1
	while i < n - 1:
		if l[i] == l[i + 1]:
			res.append([i + 1, i + 2])
			i += 2
		else:
			res.append([i + 1, i + 1])
			res.append([i + 2, i + 2])
			i += 2
		if i == n - 1:
			res.append([i + 1, i + 1])
			i += 1
	return res
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if non_zerosum(n, l) == -1:
		print(-1)
	else:
		l2 = non_zerosum(n, l)
		print(len(l2))
		for j in range(len(l2)):
			print(*l2[j])


def solve():
	n = int(input())
	a = list(map(int, input().split(' ')))
	ans = []
	count = 0
	if n % 2 == 1:
		print(-1)
	else:
		for i in range(0, n - 1, 2):
			if a[i + 1] - a[i] == 0:
				ans.append([i + 1, i + 2])
				count += 1
			else:
				ans.append([i + 1, i + 1])
				ans.append([i + 2, i + 2])
				count += 2
		print(count)
		for aa in ans:
			for i in aa:
				print(i, end=' ')
			print('')
t = int(input())
for i in range(t):
	solve()


import math
t = int(input())

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	if n % 2 != 0:
		print(-1)
	else:
		for i in range(0, n - 1, 2):
			if arr[i] == 1:
				if arr[i + 1] == 1:
					ans += [[i + 1, i + 1 + 1]]
				else:
					ans += [[i + 1, i + 1]]
					ans += [[i + 1 + 1, i + 1 + 1]]
			elif arr[i + 1] == -1:
				ans += [[i + 1, i + 1 + 1]]
			else:
				ans += [[i + 1, i + 1]]
				ans += [[i + 1 + 1, i + 1 + 1]]
		print(len(ans))
		for i in range(len(ans)):
			print(*ans[i])
while t:
	solve()
	t -= 1