Hanh lives in a shared apartment. There are $n$ people (including Hanh) living there, each has a private fridge. 

$n$ fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A fridge can be open only if all chains connected to it are unlocked. For example, if a fridge has no chains connected to it at all, then any of $n$ people can open it.

 [Image] For exampe, in the picture there are $n=4$ people and $5$ chains. The first person knows passcodes of two chains: $1-4$ and $1-2$. The fridge $1$ can be open by its owner (the person $1$), also two people $2$ and $4$ (acting together) can open it. 

The weights of these fridges are $a_1, a_2, \ldots, a_n$. To make a steel chain connecting fridges $u$ and $v$, you have to pay $a_u + a_v$ dollars. Note that the landlord allows you to create multiple chains connecting the same pair of fridges. 

Hanh's apartment landlord asks you to create exactly $m$ steel chains so that all fridges are private. A fridge is private if and only if, among $n$ people living in the apartment, only the owner can open it (i.e. no other person acting alone can do it). In other words, the fridge $i$ is not private if there exists the person $j$ ($i \ne j$) that the person $j$ can open the fridge $i$.

For example, in the picture all the fridges are private. On the other hand, if there are $n=2$ fridges and only one chain (which connects them) then both fridges are not private (both fridges can be open not only by its owner but also by another person).

Of course, the landlord wants to minimize the total cost of all steel chains to fulfill his request. Determine whether there exists any way to make exactly $m$ chains, and if yes, output any solution that minimizes the total cost. 


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $T$ ($1 \le T \le 10$). Then the descriptions of the test cases follow.

The first line of each test case contains two integers $n$, $m$ ($2 \le n \le 1000$, $1 \le m \le n$) — the number of people living in Hanh's apartment and the number of steel chains that the landlord requires, respectively.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^4$) — weights of all fridges.


-----Output-----

For each test case:

  If there is no solution, print a single integer $-1$.  Otherwise, print a single integer $c$ — the minimum total cost. The $i$-th of the next $m$ lines contains two integers $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$), meaning that the $i$-th steel chain connects fridges $u_i$ and $v_i$. An arbitrary number of chains can be between a pair of fridges. 

If there are multiple answers, print any.


-----Example-----
Input
3
4 4
1 1 1 1
3 1
1 2 3
3 3
1 2 3

Output
8
1 2
4 3
3 2
4 1
-1
12
3 2
1 2
3 1

Difficulty: EASY

Solutions:
for k in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n > 2 and m == n:
		if m >= n:
			print(sum(arr) * 2)
			for i in range(n - 1):
				print(str(i + 1) + ' ' + str(i + 2))
			print(str(n) + ' ' + str(1))
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	qwer = 0
	zxc = 0
	if n == 2 or m < n:
		print(-1)
	else:
		for i in range(n - 1):
			qwer += a[i] + a[i + 1]
			zxc += 1
		qwer += a[0] + a[n - 1]
		zxc += 1
		temp = [i for i in range(n)]
		xyz = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
		zxczxc = zxc
		while zxc < m:
			qwer += a[0] + a[1]
		print(qwer)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		while zxczxc < m:
			print(temp[0] + 1, temp[1] + 1)
			zxczxc += 1


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	if m < n or n == 2:
		print(-1)
		continue
	for i in range(n - 1):
		sum += a[i] + a[i + 1]
	sum += a[-1] + a[0]
	print(sum)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a) * 2
	for i in range(n):
		a[i] = [a[i], i + 1]
	if m < n or n == 2:
		print(-1)
		continue
	a.sort()
	s += (m - n) * (a[0][0] + a[1][0])
	print(s)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(m - n):
		print(a[0][1], a[1][0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = sum(map(int, input().split()))
	if n < 3 or m < n:
		print(-1)
	else:
		print(s * 2)
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)


from collections import *
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		d[a[i]].append(i + 1)
	b = a[:]
	if m < n or n == 2:
		print(-1)
		continue
	else:
		total = sum(a) * 2
		print(total)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n == 2:
		print(-1)
	elif n != m:
		print(-1)
	else:
		print(2 * sum(arr))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)


T = int(input())
for testCase in range(T):
	(n, m) = map(int, input().split())
	sum = 0
	for people in input().split():
		sum += int(people)
	if m < n or n == 2:
		print(-1)
		continue
	print(2 * sum)
	for i in range(m - 1):
		print(i + 1, i + 2)
	print(m, 1)


import sys

def getInput(fromFile=False):
	if fromFile:
		f = open('input', 'r')
		return lambda : f.readline()[:-1]
	return input

def main(fromFile=False):
	inp = getInput(fromFile)
	result = []
	for _ in range(int(inp())):
		count = 0
		(_, m) = list(map(int, inp().split(' ')))
		a = list(map(int, inp().split(' ')))
		if m < len(a) or len(a) in [1, 2]:
			result.append(-1)
			continue
		result.append(sum(a) * 2)
		for i in range(len(a) - 1):
			result.append(f'{i + 1} {i + 2}')
		result.append(f'{len(a)} 1')
	return result
for i in main(fromFile=False):
	print(i)


T = int(input())
for t in range(0, T):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	wt = sum(A)
	if m < n or n <= 2:
		print(-1)
	else:
		if m == n:
			print(2 * wt)
		else:
			m1 = min(A)
			B = A
			B.remove(m1)
			m2 = min(B)
			print(2 * wt + (m - n) * (m1 + m2))
			for i in range(0, m - n):
				print(A.index(m1), A.index(m2))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 2:
		print(-1)
	elif n >= 3:
		if m < n:
			print(-1)
			continue
		elif n == m:
			print(2 * sum(l))
			for i in range(1, n):
				print(i, i + 1)
			print(n, 1)


import math
import sys
from collections import defaultdict, Counter
from functools import lru_cache
t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	if b < a or a == 2:
		print(-1)
	elif a == b:
		ans = 2 * sum(arr)
		print(ans)
		for i in range(1, a):
			print(*[i, i + 1])
		print(*[a, 1])


from sys import maxsize
for _ in range(int(input())):
	(N, M) = list(map(int, input().split()))
	cost = list(map(int, input().split()))
	if N > M or N == 2:
		print(-1)
	else:
		min1 = maxsize
		min2 = maxsize
		idx1 = -1
		idx2 = -1
		for (idx, val) in enumerate(cost):
			if val <= min1:
				(min1, min2) = (val, min1)
				(idx1, idx2) = (idx, idx1)
			elif val < min2:
				idx2 = idx
				min2 = val
		print(2 * sum(cost) + (min1 + min2) * (M - N))
		for idx in range(N):
			print(idx + 1, (idx + 1) % N + 1)
		for _ in range(M - N):
			print(idx1, idx2)


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter

def solve():
	(n, m) = MAP()
	a = LI()
	if m < n or n == 2:
		print(-1)
	else:
		print(2 * sum(a))
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)
for i in range(IN()):
	solve()


t = int(input())
for i in range(t):
	lis = input().split()
	n = int(lis[0])
	m = int(lis[1])
	lis1 = input().split()
	k = 0
	if n == 2:
		print(-1)
	elif n > m:
		print(-1)
	elif n == m:
		sum1 = 0
		for j in range(n):
			lis1[j] = int(lis1[j])
			sum1 += lis1[j]
		print(sum1 * 2)
		for j in range(1, n):
			print(j, j + 1)
		print(n, 1)
	else:
		sum = 0
		sum1 = 0
		sum2 = 0
		for j in range(n):
			lis1[j] = int(lis1[j])
			sum1 += lis1[j]
		sum2 = sum1
		lis1.sort()
		a = lis1[0]
		b = lis1[1]
		c = lis1[2]
		sum1 = sum1 - a
		sum2 = sum2 - b
		for j in range(n):
			if j == 0:
				sum += sum1
			elif j == 1:
				sum += sum2
			else:
				sum += a + b
		k = m - (n - 2 + n - 1)
		sum += k * (a + b)
		print(sum)
		for j in range(n):
			if j == 0:
				print(1, 2)
			elif j == 1:
				print(1 + 1, 2 + 1)
			elif j != 2:
				print(j + 1, 1)
				print(j + 1, 2)
			else:
				print(j + 1, 1)
		for j in range(k):
			print(1, 2)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	li = list(map(int, input().split()))
	if b >= a and b != 2:
		print(2 * sum(li))
		for i in range(1, a):
			print(i, i + 1)
		print(a, 1)
	else:
		print(-1)


x = eval(input())
for i in range(x):
	y = input().split(' ')
	n = int(y[0])
	m = int(y[1])
	s = []
	c = 0
	z = list(map(int, input().split(' ')))
	for j in range(len(z)):
		c += z[j]
		z[j] = (z[j], j + 1)
	z = sorted(z)
	for j in range(n - 1):
		s = s + [(str(j + 1), str(j + 2))]
	s = s + [(str(n), str(1))]
	if m < n or n == 2:
		print('-1')
	else:
		print(2 * c)
		for j in range(m):
			print(' '.join(s[j]))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		cost = 2 * sum(a)
		ind = [i for i in range(1, n + 1)]
		ind.sort(key=lambda x: a[x - 1])
		cost += (m - n) * (a[ind[0] - 1] + a[ind[1] - 1])
		print(cost)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for i in range(m - n):
			print(ind[0], ind[1])


def main():
	t = int(input())
	for i in range(t):
		(n, m) = input().split()
		n = int(n)
		m = int(m)
		a = input().split()
		suma = 0
		for j in range(n):
			suma += int(a[j])
			a[j] = (j + 1, int(a[j]))
		if n <= 2:
			print(-1)
		elif m < n:
			print(-1)
		elif m == n:
			print(suma * 2)
			for j in range(1, n + 1):
				if j == n:
					print(str(n) + ' 1')
				else:
					print(str(j) + ' ' + str(j + 1))
		else:
			a.sort(key=lambda x: x[0])
			print(suma * 2 + (a[0][1] + a[1][1]) * (m - n))
			for j in range(1, n + 1):
				if j == n:
					print(str(n) + ' 1')
				else:
					print(str(j) + ' ' + str(j + 1))
			for j in range(m - n):
				print(str(a[0][0]) + ' ' + str(a[1][0]))
main()


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	if b < a or a == 2:
		print(-1)
		input()
	else:
		print(2 * sum(map(int, input().split())))
		for i in range(a - 1):
			print(i + 1, i + 2)
		print(a, 1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [(i + 1, c) for (i, c) in enumerate(map(int, input().split()))]
	a = sorted(a, key=lambda x: x[1])
	sumc = 0
	for i in range(n):
		sumc += a[i][1]
	if m < n or n == 2:
		print(-1)
	else:
		ans = 2 * sumc
		print(ans)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	(n, m) = l()
	A = l()
	if n == 2:
		print(-1)
		continue
	A = [[A[i], i + 1] for i in range(n)]
	ans = []
	cost = 0
	for i in range(n):
		ans.append([A[i][1], A[(i + 1) % n][1]])
		cost += A[i][0] + A[(i + 1) % n][0]
	if len(ans) > m:
		print(-1)
		continue
	print(cost)
	for ele in ans:
		print(*ele)


def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n > m or n <= 2:
		print(-1)
		return -1
	a1 = [a[0], 0]
	a2 = [a[1], 1]
	if a1[0] > a2[0]:
		(a1, a2) = (a2, a1)
	for (i, b) in enumerate(a[2:]):
		if b < a2[0]:
			if b < a1[0]:
				(a1, a2) = ([b, i + 2], a1)
			else:
				a2 = [b, i + 2]
	res = sum(a) * 2 + (m - n) * (a1[0] + a2[0])
	print(res)
	for i in range(n):
		print(i + 1, (i + 1) % n + 1)
	for i in range(m - n):
		print(a1[1] + 1, a2[1] + 1)
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l2 = list(map(int, input().split()))
	l = sorted(l2)
	if n == 2 or m < n:
		print(-1)
		continue
	ans = 2 * sum(l)
	ans += (m - n) * (l[0] + l[1])
	print(ans)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(m - n):
		print(l2.index(l[0]) + 1, l2.index(l[1]) + 1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	w = 0
	z = 0
	c = []
	if m < n or n < 3:
		print(-1)
	elif n == m:
		print(sum(a) * 2)
		for i in range(1, n):
			b.append([i, i + 1])
		b.append([n, 1])
		for i in range(len(b)):
			print(*b[i])


for z in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n <= m and n > 2:
		print(2 * sum(a))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
	else:
		print(-1)


import sys

def I():
	return sys.stdin.readline().rstrip()
for _ in range(int(I())):
	(n, m) = map(int, I().split())
	a = list(map(int, I().split()))
	if n > m or n == 2:
		print(-1)
	else:
		s = 2 * sum(a)
		b = sorted(a)
		i = a.index(b[0])
		a[i] = 100000.0
		j = a.index(b[1])
		m -= n
		s += sum(b[:2]) * m
		print(s)
		for k in range(n):
			print(k + 1, (k + 1) % n + 1)
		for k in range(m):
			print(i + 1, j + 1)


def answer(people, steelCount, weights):
	if steelCount < people or people == 2:
		return print(-1)
	totalFee = sum(weights) * 2
	nodeRelations = []
	for node in range(1, len(weights)):
		nodeRelations.append([node, node + 1])
	nodeRelations.append([len(weights), 1])
	if steelCount > people:
		remainder = steelCount - people
		sortedWeights = sorted(weights)
		min1 = sortedWeights[0]
		min1Index = weights.index(min1)
		min2 = sortedWeights[1]
		min2Index = weights.index(min2)
		totalFee += (min1 + min2) * remainder
		for _ in range(remainder):
			nodeRelations.append([min1Index, min2Index])
	print(totalFee)
	for nr in nodeRelations:
		print(str(nr[0]) + ' ' + str(nr[1]))
testCount = int(input())
for _ in range(testCount):
	(n, m) = map(int, input().split())
	weights = list(map(int, input().split()))
	answer(n, m, weights)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = list(map(int, input().split()))
	if n == 2:
		print(-1)
		continue
	min1 = c.index(min(c))
	min2 = 1 if min1 == 0 else 0
	for i in range(n):
		if c[i] < c[min2] and i != min1:
			min2 = i
	emin = c[min1] + c[min2]
	if m >= n:
		print(sum(c) * 2 + (m - n) * emin)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m - n):
			print(min1 + 1, min2 + 1)
	else:
		print(-1)


import sys

def main():
	input_list = get_input()
	for line in range(len(input_list[1:])):
		if line % 2 == 0:
			n = int(input_list[line + 1].split(' ')[0])
			m = int(input_list[line + 1].split(' ')[1])
		else:
			a = [int(x) for x in input_list[line + 1].split(' ')]
			if n == m and n != 2:
				solve(n, m, a)
			else:
				print(-1)

def get_input():
	input_list = []
	for line in sys.stdin:
		input_list.append(line.rstrip('\n'))
	return input_list

def solve(n, m, a):
	cost = sum(a) * 2
	print(cost)
	for i in range(1, len(a)):
		print(str(i) + ' ' + str(i + 1))
	print(str(len(a)) + ' 1')
	return None
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n <= 2:
		print('-1')
		continue
	if m <= n - 1:
		print('-1')
		continue
	l.sort()
	li = []
	res = 0
	i = 0
	while i < m:
		i += 1
		if i == n:
			break
		res = res + l[i] + l[i - 1]
		li.append([i, i + 1])
	i += 1
	li.append([n, 1])
	res = res + l[n - 1] + l[0]
	while i <= m:
		i += 1
		res = res + l[0] + l[1]
		li.append([1, 2])
	print(res)
	for (i, j) in li:
		print(i, j)


for t in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	if n != m or n == 2:
		print(-1)
	else:
		print(2 * sum(a))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)


def small(arr):
	freq = {}
	for i in range(len(arr)):
		freq[arr[i]] = i
	arr = list(set(arr))
	if len(arr) == 1:
		return (0, 1)
	arr.sort()
	small = freq[arr[0]]
	sec_small = freq[arr[1]]
	return (small, sec_small)

def graph(arr, n, m):
	empty = []
	a = 1
	b = a + 1
	temp = n
	s = 0
	s = sum(arr) * 2
	while temp > 0:
		if a == n:
			a = n
			b = 1
		empty.append((a, b))
		a = b
		b = a + 1
		temp -= 1
	print(s)
	for i in empty:
		print(i[0], i[1])
t = int(input())
for i in range(t):
	inp = input().split()
	n = int(inp[0])
	m = int(inp[1])
	arr = list(map(int, input().split()))
	if m <= n - 1 or n == 2:
		print(-1)
	else:
		graph(arr, n, m)


def solve(n, m, costs):
	if n == 2:
		print(-1)
		return
	if m < n:
		print(-1)
		return
	cost = 0
	for i in range(n - 1):
		cost += costs[i] + costs[i + 1]
	cost += costs[0] + costs[-1]
	min_cost = float('inf')
	for i in range(n):
		for j in range(i + 1, n):
			cost1 = costs[i] + costs[j]
			if cost < min_cost:
				min_cost = cost1
				min_pair = [i + 1, j + 1]
	m -= n
	cost += m * min_cost
	print(cost)
	for i in range(n - 1):
		print(i + 1, i + 2)
	print(n, 1)
	for i in range(m):
		print(min_pair[0], min_pair[1])

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		costs = list(map(int, input().split()))
		solve(n, m, costs)
main()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = input().split()
	if m < n or n == 2:
		print(-1)
	else:
		summa = 0
		for b in arr:
			summa += int(b)
		print(summa * 2)
		for k in range(1, n):
			print(k, k + 1)
		print(k + 1, 1)


a = int(input())
for i in range(0, a):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = sum(arr)
	if n > m or n == 2:
		print(-1)
	else:
		print(2 * ans)
		for i in range(1, n + 1):
			if i == n:
				print(n, 1)
			else:
				print(i, i + 1)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
	else:
		print(sum(a) * 2)
		for i in range(0, m - 1):
			print(i + 1, i + 2)
		print(n, 1)


from math import ceil
from math import factorial
from collections import defaultdict
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for i in range(t):
	(a, b) = iia()
	x = iia()
	if a > b:
		print(-1)
	elif a == 2:
		print(-1)
	else:
		print(2 * sum(x))
		for i in range(a - 1):
			print(i + 1, i + 2)
		print(a, 1)


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n:
		print(-1)
		continue
	elif m == n:
		if n == 2:
			print(-1)
			continue
		else:
			print(2 * sum(a))
			for i in range(n - 1):
				print(i + 1, i + 2)
			print(n, 1)
	else:
		1 / 0


for _ in [0] * int(input()):
	(n, m) = list(map(int, input().split()))
	weight = {}
	cost = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		print(sum(cost) * 2)
		for i in range(1, n):
			print(str(i) + ' ' + str(i + 1))
		print(str(n) + ' ' + str(1))


q = int(input())
for qq in range(q):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		b.append([a[i], i + 1])
	s = 2 * sum(a)
	b.sort(key=lambda x: x[0])
	if n == 2:
		print(-1)
		continue
	if n > m:
		print(-1)
	else:
		print(s + (b[0][0] + b[1][0]) * (m - n))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m - n):
			print(b[0][1], b[1][1])


T = int(input())
for t in range(T):
	(n, m) = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	if m < n or n == 2:
		print(-1)
	else:
		w.sort()
		print(2 * sum(w))
		for k in range(n - 1):
			print(k + 1, k + 2)
		print(n, 1)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	dop = list(map(int, input().split()))
	suma = sum(dop)
	mas = []
	for i in range(n):
		mas.append([dop[i], i])
	if m < n or n == 2:
		print(-1)
		continue
	mas.sort()
	print(suma * 2 + (mas[0][0] + mas[1][0]) * (m - n))
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(m - n):
		print(mas[0][1] + 1, mas[1][1] + 1)


from itertools import combinations
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n == 2:
		print('-1')
		continue
	if n == m:
		cost = 0
		ans = []
		for _i in range(1, n):
			ans.append([_i, _i + 1])
		for _i in range(0, n):
			cost += arr[_i - 1] + arr[_i]
		ans.append([n, 1])
		print(cost)
		for _i in ans:
			print(' '.join(map(str, _i)))
	else:
		print('-1')


from itertools import permutations
for testcase in range(int(input())):
	(fridge, chains) = list(map(int, input().split()))
	prices = list(map(int, input().split()))
	if fridge <= 2:
		print(-1)
	elif chains - fridge < 0:
		print(-1)
	else:
		print(sum(prices) * 2)
		for x in range(1, fridge + 1):
			if x == fridge:
				print(x, 1)
			else:
				print(x, x + 1)


import sys
from collections import deque
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	(n, m) = map(int, ip().split())
	a = list(map(int, ip().split()))
	if n < 3 or m < n:
		print(-1)
		continue
	ans = []
	cost = 0
	for i in range(1, n):
		ans.append([i, i + 1])
	ans.append([n, 1])
	print(2 * sum(a))
	for i in ans:
		print(*i)


t = int(input())
out = []
for i in range(t):
	nm = [int(c) for c in input().split()]
	na = [int(c) for c in input().split()]
	if nm[1] < nm[0] or nm[1] < 3:
		out.append([-1, 0])
	else:
		kq = []
		s = na[-1] + na[0]
		for j in range(0, nm[0] - 1):
			kq.append(str(j + 1) + ' ' + str(j + 2))
			s = s + na[j] + na[j + 1]
		kq.append(str(nm[0]) + ' ' + '1')
		kq.insert(0, str(s))
		out.append(kq)
for i in range(t):
	if out[i][0] == -1:
		print(-1)
	else:
		print(out[i][0])
		for j in range(1, len(out[i])):
			print(out[i][j])


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	weights = list(map(int, input().split()))
	temp = sorted(weights)
	if n == 2 or m < n:
		print(-1)
	else:
		a = weights.index(temp[0]) + 1
		b = weights.index(temp[1]) + 1
		if a == b:
			b += 1
		cost = 2 * sum(weights) + (m - n) * (temp[0] + temp[1])
		print(cost)
		for i in range(1, n):
			print(f'{i} {i + 1}')
		print(f'{n} {1}')
		m -= n
		while m > 0:
			print(f'{a} {b}')
			m -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	weights = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		weights.sort()
		(i, j) = (0, 1)
		ans = [(i + 1, 1 + (i + 1) % n) for i in range(n)]
		mini = 2 * sum(weights)
		for pair in range(m - n):
			mini += weights[i] + weights[j]
			ans.append((i + 1, j + 1))
			j += 1
			if j == n:
				i += 1
				j = i + 1
				if i == n:
					i = 0
					j = 1
		print(mini)
		for pair in ans:
			print(*pair)


def print2Smallest(arr):
	index1 = 0
	index2 = 0
	arr_size = len(arr)
	first = second = 100000
	for i in range(0, arr_size):
		if arr[i] < first:
			second = first
			first = arr[i]
			index1 = i
		elif arr[i] < second:
			second = arr[i]
			index2 = i
	return (first, second, index1, index2)
t = int(input())
for i in range(t):
	(nof, noc) = map(int, input().split(' '))
	arr = [int(arr) for arr in input().split(' ')]
	total = 0
	if noc < nof or nof <= 2:
		print(-1)
	elif noc == nof:
		total += 2 * sum(arr)
		print(total)
		for i in range(noc - 1):
			print(str(i + 1) + ' ' + str(i + 2))
		print(str(noc) + ' ' + str(1))
	elif noc > nof:
		x = print2Smallest(arr)
		min1 = x[0]
		min2 = x[1]
		f1 = x[2] + 1
		f2 = x[3] + 1
		total += 2 * sum(arr)
		left = noc - nof
		total += left * (min1 + min2)
		print(total)
		for i in range(nof - 1):
			print(str(i + 1) + ' ' + str(i + 2))
		print(str(nof) + ' ' + str(1))
		for i in range(left):
			print(str(f1) + ' ' + str(f2))


T = int(input())
for c in range(T):
	(n, m) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	if m < n or n < 3:
		print(-1)
	else:
		print(2 * sum(a))
		for i in range(n):
			if i + 2 == n:
				print(i + 1, i + 2)
			else:
				print(i + 1, (i + 2) % n)


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def sortFirst(val):
	return val[0]

def paint(pic, x, y):
	pass

def main():
	t = rsingle_int()
	for _ in range(t):
		(n, m) = rmult_int()
		a = rmult_int()
		if n <= 2 or m < n:
			print(-1)
		else:
			cost = sum(a) * 2
			min_cost = a[0]
			min_cost_i = 0
			for i in range(len(a)):
				if a[i] < min_cost:
					min_cost = a[i]
					min_cost_i = i
			min_cost_2 = 100000
			for i in range(len(a)):
				if i != min_cost_i and a[i] < min_cost_2:
					min_cost_2 = a[i]
					min_cost_2_i = i
			min_cost_pair = min_cost + min_cost_2
			cost += (m - n) * min_cost_pair
			print(cost)
			for i in range(m):
				if i < n - 1:
					print('{} {}'.format(i + 1, i + 2))
				elif i == n - 1:
					print('{} {}'.format(i + 1, 1))
				else:
					print('{} {}'.format(min_cost_i + 1, min_cost_2_i + 1))
main()


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(n, m) = value()
	a = arr()
	if n == 2 or m < n:
		print(-1)
	else:
		res = []
		for i in range(n):
			res += [(i + 1, a[i])]
		res.sort(key=lambda x: x[1])
		ans = sum(a) * 2 + (res[0][1] + res[1][1]) * (m - n)
		print(ans)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for i in range(m - n):
			print(res[0][1], res[1][1])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if n == 2 or m < n:
		print(-1)
		continue
	for i in range(len(a)):
		a[i] = (a[i], i + 1)
	a.append(a[0])
	ans = 0
	anss = []
	pr = 0
	while pr != m:
		for i in range(1, n + 1):
			if pr == m:
				break
			ans += a[i - 1][0] + a[i][0]
			anss.append((a[i - 1][1], a[i][1]))
			pr += 1
	print(ans)
	for i in anss:
		print(*i)


import sys
from collections import defaultdict as dd

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def strl():
	return list(strsp())

def sp():
	return map(int, data().split())

def strsp():
	return map(str, data().split())
for _ in range(int(data())):
	(n, m) = sp()
	a = l()
	if n == 2:
		print(-1)
	elif m != n:
		print(-1)
	else:
		print(2 * sum(a))
		(c, d) = (1, 2)
		for i in range(m):
			if d == n:
				print(c, d)
				d = 1
				c += 1
			else:
				print(c, d)
				c += 1
				d += 1


import sys
import math, collections
input = sys.stdin.readline

def pr(*args, **kwargs):
	print(*args, **{'end': '', **kwargs})

def prln(*args, **kwargs):
	print(*args, **kwargs)

def fill(arr, val):
	for i in range(len(arr)):
		if isinstance(arr[i], list):
			fill(arr[i], val)
		else:
			arr[i] = val

def ls(*dims):
	if len(dims) == 0:
		return []
	a = dims[::-1]
	res = [0] * a[0]
	for i in a[1:]:
		res = [res.copy() for _ in range(i)]
	return res
rowin = lambda : list(map(int, input().split()))
numin = lambda : int(input())
T = numin()
for T_ in range(T):
	(n, m) = rowin()
	w = sorted(rowin())
	if m < n or n == 2:
		prln(-1)
		continue
	prln(sum(w) * 2)
	z = w + [w[0]]
	for i in range(n):
		prln(i + 1, (i + 1) % n + 1)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	w = [int(x) for x in input().split()]
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		sumv = 0
		w.sort()
		coord = []
		for i in range(1, n):
			sumv += w[i] + w[i - 1]
			coord.append([i, i + 1])
		for i in range(n, m):
			sumv += w[0] + w[1]
			coord.append([1, 2])
		sumv += w[-1] + w[0]
		coord.append([n, 1])
		print(sumv)
		for i in coord:
			print(*i)


import sys
import math
from collections import defaultdict, Counter, deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 2 or n != m:
		print(-1)
	else:
		ans = sum(a) * 2
		print(ans)
		for j in range(1, n):
			print(j, j + 1)
		print(j + 1, 1)


t = int(input())
ns = []
ms = []
arrs = []
for i in range(t):
	temp = [int(i) for i in input().split(' ')]
	ns.append(temp[0])
	ms.append(temp[1])
	arrs.append([int(i) for i in input().split(' ')])
for i in range(t):
	if ns[i] > ms[i] or ns[i] < 3:
		print(-1)
	else:
		vr = sorted(arrs[i])
		print(sum(arrs[i]) * 2 + (ms[i] - ns[i]) * (vr[0] + vr[1]))
		for j in range(ns[i]):
			if j == ns[i] - 1:
				print(j + 1, 1)
			else:
				print(j + 1, j + 2)
		if ms[i] > ns[i]:
			for j in range(ms[i] - ns[i]):
				print('1 2')


for __ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	for i in range(a):
		ar[i] = [ar[i], i + 1]
	if a <= 2 or b < a:
		print(-1)
	else:
		ar.sort()
		ans = 0
		lol = []
		ar.sort()
		for j in range(b - a):
			lol.append([ar[0][1], ar[1][1]])
			ans += ar[0][0] + ar[1][0]
		for i in range(1, a + 1):
			lol.append([i, i % a + 1])
			ans += ar[i - 1][0] + ar[i % a][0]
		print(ans)
		for elem in lol:
			print(*elem)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
		continue
	cost = 2 * sum(a)
	edges_used = n
	extra_edges = m - n
	(x, y) = (float('inf'), float('inf'))
	(x_, y_) = (0, 0)
	for i in range(n):
		if a[i] < x:
			if a[i] < y:
				x = y
				x_ = y_
				y = a[i]
				y_ = i
			else:
				x = a[i]
				x_ = i
	(minm1, minm2) = (y, x)
	cost += extra_edges * (minm1 + minm2)
	print(cost)
	for i in range(extra_edges):
		print(y_ + 1, x_ + 1)
	for i in range(m):
		print(max(i + 1, 1), max((i + 2) % (m + 1), 1))


def answer(people, steelCount, weights):
	if steelCount < people or people == 2:
		return print(-1)
	totalFee = sum(weights) * 2
	nodeRelations = []
	for node in range(1, len(weights)):
		nodeRelations.append([node, node + 1])
	nodeRelations.append([len(weights), 1])
	print(totalFee)
	for nr in nodeRelations:
		print(str(nr[0]) + ' ' + str(nr[1]))
testCount = int(input())
for _ in range(testCount):
	(n, m) = map(int, input().split())
	weights = list(map(int, input().split()))
	answer(n, m, weights)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	tot = sum(A)
	A = [(A[i], i + 1) for i in range(n)]
	A.sort()
	if m < n or n == 2:
		print(-1)
	else:
		cost = 2 * tot
		cost += (m - n) * (A[0][0] + A[1][0])
		print(cost)
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)
		for i in range(m - n):
			print(A[0][1], A[1][1])


for _ in '0' * int(input()):
	(n, m) = map(int, input().split())
	ns = map(int, input().split())
	if n != m or n == 2:
		print(-1)
		continue
	print(sum(ns) * 2)
	for i in range(1, m + 1):
		print(i, i + 1 if i + 1 < m + 1 else 1)


t = int(input())
for j in range(t):
	(n, m) = [int(x) for x in input().split()]
	ws = [int(x) for x in input().split()]
	if m < n or n <= 2:
		print(-1)
	else:
		ws = sorted(ws)
		total = 0
		ans = []
		for i in range(m):
			uIndex = i % n
			vIndex = (i + 1) % n
			u = ws[uIndex]
			v = ws[vIndex]
			total += u + v
			ans.append(str(uIndex + 1) + ' ' + str(vIndex + 1))
		print(total)
		print('\n'.join(ans))


t = int(input())
while t > 0:
	(n, m) = [int(ele) for ele in input().split()]
	a = [int(ele) for ele in input().split()]
	if n != m or n == 2:
		print(-1)
	else:
		s = 0
		for ele in a:
			s += 2 * ele
		print(s)
		for i in range(1, n + 1):
			if i != n:
				print(i, i + 1)
			else:
				print(i, 1)
	t -= 1


t = int(input())
for it in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
		continue
	m1 = 0
	m2 = 1
	if a[m1] > a[m2]:
		(m1, m2) = (m2, m1)
	for i in range(2, n):
		if a[i] < a[m1]:
			(m1, m2) = (i, m1)
		elif a[i] < a[m2]:
			m2 = i
	ans = sum(a) * 2 + (a[m1] + a[m2]) * (m - n)
	print(ans)
	for i in range(n):
		print(i + 1, (i + 1) % n + 1)
	for i in range(m - n):
		print(m1 + 1, m2 + 1)


import sys
import collections
from collections import Counter
import itertools
import math
import timeit
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	(n, m) = mi()
	d = li()
	res = []
	if m < n or n == 2:
		print(-1)
	else:
		print(sum(d) * 2)
		res = [f'{i} {i + 1}' for i in range(1, n)]
		res.append(f'{n} 1')
		prr(res, sep='\n')


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	(n, m) = rl()
	A = rl()
	if m < n or n == 2:
		print(-1)
		return
	(m1, m2) = (10 ** 10, 10 ** 10)
	(i1, i2) = (-1, -1)
	for (i, a) in enumerate(A):
		if a <= m1:
			m2 = m1
			i2 = i1
			m1 = a
			i1 = i + 1
		elif a < m2:
			m2 = a
			i2 = i + 1
	cheapest = m2 + m1
	print(sum(A) * 2 + cheapest * (m - n))
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(m - n):
		print(i1, i2)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
for _ in range(ii()):
	(n, k) = kk()
	if k < n or n < 3:
		kk()
		print(-1)
	else:
		print(sum(kk()) * 2)
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_str():
	return list(sys.stdin.readline().split())
for _ in range(inp()):
	(N, M) = inpl()
	aaa = inpl()
	aa = [(x, i + 1) for (i, x) in enumerate(aaa)]
	aa.sort()
	if N <= M and N != 2:
		ans = sum(aaa) * 2 + (aa[0][0] + aa[1][0]) * (M - N)
		print(ans)
		ansl = [str(i) + ' ' + str(i + 1) for i in range(1, N)] + [str(N) + ' 1']
		print('\n'.join(ansl))
		if N != M:
			zan = [str(aa[0][1]) + ' ' + str(aa[1][1])] * (M - N)
			print('\n'.join(zan))
	else:
		print(-1)


A = []
x = int(input())
for i in range(x):
	(a, b) = map(int, input().split())
	B = list(map(int, input().split()))
	if a <= 2 or b < a:
		A.append(-1)
	else:
		A.append([0, []])
		z1 = max(B) + 1
		z2 = int(z1) + 1
		ind1 = 0
		ind2 = 0
		for j in range(len(B)):
			if B[j] < z2:
				if B[j] < z1:
					z2 = int(z1)
					ind2 = int(ind1)
					ind1 = j
					z1 = B[j]
				else:
					z2 = B[j]
					ind2 = j
		for i in range(1, a):
			A[-1][-1].append((i, i + 1))
		A[-1][-1].append((a, 1))
		for i in range(b - a):
			A[-1][-1].append((ind1 + 1, ind2 + 1))
		A[-1][0] = sum(B) * 2 + (z1 + z2) * (b - a)
for t in A:
	if type(t) is int:
		print(t)
	else:
		print(t[0])
		for gh in t[1]:
			print(*gh)


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, m) = R()
	r = range(1, n + 1)
	a = (*R(),)
	((x, i), (y, j)) = sorted(zip(a, r))[:2]
	if n < 3 or m < n:
		print(-1)
	else:
		print(2 * sum(a) + (x + y) * (m - n))
		for k in r:
			print(k, k % n + 1)
		for _ in range(m - n):
			print(i, j)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [pow(10, 10)] + list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
	else:
		res = []
		min1 = min(a)
		minp1 = a.index(min1)
		a.remove(min1)
		min2 = min(a)
		minp2 = a.index(min2)
		if minp2 >= minp1:
			minp2 += 1
		a.insert(minp1, min1)
		price = 0
		for i in range(1, n + 1):
			if i == n:
				temp = str(i) + ' ' + str(1)
				price += a[i] + a[1]
			else:
				temp = str(i) + ' ' + str(i + 1)
				price += a[i] + a[i + 1]
			res.append(temp)
		for i in range(m - n):
			temp = str(minp1) + ' ' + str(minp2)
			price += min1 + min2
			res.append(temp)
		print(price)
		for i in res:
			print(i)


def do_it():
	s = input().split()
	n = int(s[0])
	m = int(s[1])
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print('-1')
		return
	print(sum(a) * 2)
	for i in range(1, n):
		print('%d %d' % (i, i + 1))
	print('%d %d' % (n, 1))

def main():
	t = int(input())
	while t:
		do_it()
		t -= 1
main()


q = int(input())
(index, index2) = (0, 0)
for _ in range(q):
	(n, m) = list(map(int, input().split(' ')))
	w = weights = [0] * n
	w = list(map(int, input().split(' ')))
	if m < n:
		print(-1)
		continue
	if n == 2:
		print(-1)
		continue
	temp = 10000
	for i in range(n):
		if temp > w[i]:
			temp = w[i]
			index = i
	w[index] = 10000
	temp2 = 10000
	for i in range(n):
		if temp2 > w[i]:
			temp2 = w[i]
			index2 = i
	w[index] = temp
	cost = 2 * sum(w)
	cost += (m - n) * (temp + temp2)
	print(cost)
	for i in range(m - 1):
		print(i + 1, i + 2)
	print(m, 1)
	for i in range(m - n):
		print(index + 1, index2 + 1)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	(n, m) = multi_int_input()
	weight = list_input()
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		fridge_list = []
		for (i, k) in enumerate(weight):
			fridge_list.append([k, i + 1])
		sorted_fridges = sorted(fridge_list)
		first_pass = 0
		arrangement = []
		cost = 0
		for i in range(0, n - 1):
			arrangement.append([i + 1, i + 2])
			cost += weight[i] + weight[i + 1]
			if i == n - 2:
				arrangement.append([i + 2, 1])
				cost += weight[i + 1] + weight[0]
		if len(arrangement) < m:
			while len(arrangement) < m:
				arrangement.append([sorted_fridges[0][1], sorted_fridges[1][1]])
				cost += sorted_fridges[0][0] + sorted_fridges[1][0]
		print(cost)
		for i in arrangement:
			print(*i)


for _ in range(int(input())):
	nm = [int(x) for x in input().split()]
	weights = [int(x) for x in input().split()]
	n = nm[0]
	m = nm[1]
	if m < n or n <= 2:
		print(-1)
		continue
	fridges = {}
	for i in range(n):
		fridges[i] = (i, weights[i])
	chains = []
	chain_amt = {}
	for i in range(n):
		chain_amt[i] = 0
	ans = 0
	for i in range(n):
		if i + 1 < n:
			chains.append((fridges[i], fridges[i + 1]))
			ans += fridges[i][1] + fridges[i + 1][1]
		else:
			chains.append((fridges[i], fridges[0]))
			ans += fridges[i][1] + fridges[0][1]
	print(ans)
	for i in range(len(chains)):
		print(chains[i][0][0] + 1, chains[i][1][0] + 1)


t = int(input())
for i in range(t):
	a = input()
	a = a.split()
	f = int(a[1]) - int(a[0])
	b = input()
	b = b.split()
	b.sort()
	b = [int(b[x]) for x in range(len(b))]
	if f < 0 or (int(a[0]) == 2 and int(a[1]) == 2):
		print(-1)
	else:
		s = 2 * sum(b)
		print(s)
		for x in range(int(a[0])):
			print(x + 1, (x + 1) % int(a[0]) + 1)


def test_case() -> str:
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	weights = [int(x) for x in input().split()]
	if m < n or n == 2:
		return -1
	if m == n:
		s = str(2 * sum(weights))
		for i in range(n):
			s += '\n' + str(i + 1) + ' ' + str((i + 1) % n + 1)
		return s

def run():
	test_cases = int(input())
	statements = []
	for i in range(test_cases):
		statements.append(test_case())
	for statement in statements:
		print(statement)
run()


n = int(input())
for nn in range(n):
	val = [int(x) for x in input().split(' ')]
	(n, m) = (val[0], val[1])
	chains = [int(x) for x in input().split(' ')]
	failed = False
	if n == 2:
		failed = True
	if m < n:
		failed = True
	if failed:
		print('-1')
	if not failed:
		first_min = 0 if chains[0] < chains[1] else 1
		second_min = 1 if chains[0] < chains[1] else 0
		for i in range(2, n):
			if chains[i] < chains[first_min]:
				second_min = first_min
				first_min = i
			elif chains[i] < chains[second_min]:
				second_min = i
		easy = 0
		total = 0
		locked = []
		for i in range(n - 1):
			locked.append((i, i + 1))
			total += chains[i] + chains[i + 1]
		locked.append((n - 1, 0))
		total += chains[n - 1] + chains[0]
		extra = m - n
		print(total + extra * (chains[first_min] + chains[second_min]))
		for i in range(len(locked)):
			print(locked[i][0] + 1, locked[i][1] + 1)
		for i in range(extra):
			print(first_min + 1, second_min + 1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	kam = [(arr[i], i + 1) for i in range(n)]
	kam.sort()
	cost = 0
	extra = 0
	if m < n or n < 3:
		print(-1)
	else:
		cost = 2 * sum(arr)
		extra = m - n
		cost += extra * (kam[0][0] + kam[1][0])
		print(cost)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for i in range(extra):
			print(kam[0][1], kam[1][1])


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	cost = 0
	for elem in input().split():
		cost += int(elem)
	if m < n or n == 2:
		print(-1)
		continue
	print(2 * cost)
	for i in range(m - 1):
		print(i + 1, i + 2)
	print(m, 1)


import math
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	if m < n or m > n * (n - 1) // 2:
		print('-1')
		continue
	base_cost = sum(a) * 2
	a.sort()
	cost = base_cost + (m - n) * (a[0] + a[1])
	print(cost)
	for i in range(n):
		if i == n - 1:
			print(n, 1)
		else:
			print(i + 1, i + 2)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	alist = [int(x) for x in input().split(' ')]
	blist = alist[:]
	if n == 2 or m < n:
		print('-1')
	else:
		alist.remove(min(alist))
		print(2 * sum(blist) + (m - n) * (min(blist) + min(alist)))
		for i in range(n - 1):
			print(i + 1, i + 2, sep=' ')
		print(n, 1, sep=' ')
		a = blist.index(min(blist))
		b = alist.index(min(alist))
		if b >= a:
			for i in range(m - n):
				print(a + 1, b + 2, sep=' ')
		else:
			for i in range(m - n):
				print(b + 1, a + 1, sep=' ')


def evaluate(i):
	weights = i[1]
	total = 0
	edges = []
	for j in range(len(weights)):
		total = total + weights[j % len(weights)] + weights[(j + 1) % len(weights)]
		index1 = j + 1
		if j + 2 > len(weights):
			index2 = (j + 2) % len(weights)
		else:
			index2 = j + 2
		edges.append((index1, index2))
	print(total)
	for k in edges:
		print(*k)
T = int(input())
data = []
while T > 0:
	nm = list(map(int, input().split()))
	w = list(map(int, input().split()))
	data.append((nm, w))
	T -= 1
for i in data:
	if i[0][0] == 2:
		print(-1)
	elif i[0][1] < i[0][0]:
		print(-1)
	else:
		evaluate(i)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = [*list(map(int, input().split()))]
	if m < n or (n == 2 and m == 2):
		print(-1)
	else:
		cost = x = y = 0
		mn = float('inf')
		for i in range(n):
			t = a[i] + a[i - 1]
			cost += t
			if t < mn:
				mn = min(mn, t)
				(x, y) = (i + 1, n if i == 0 else i)
		print(cost + (m - n) * mn)
		for i in range(n - 1):
			print(i + 1, (i + 2) % (n + 1))
		print(n, 1)
		for i in range(m - n):
			print(x, y)


for _ in range(int(input())):
	(n, m) = [int(___) for ___ in input().split()]
	fridges = [int(__) for __ in input().split()]
	if n == 2:
		print(-1)
		continue
	if n > m:
		print(-1)
	else:
		print(2 * sum(fridges))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)


t = int(input())
for nt in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		left = m - n
		cost = sum(l) * 2
		min1 = min(l)
		i1 = l.index(min1)
		min2 = 100000000000000000
		for i in range(len(l)):
			if i != i1 and l[i] >= min1 and (l[i] < min2):
				min2 = l[i]
				i2 = i
		cost += left * (min1 + min2)
		print(cost)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for i in range(left):
			print(i1 + 1, i2 + 1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	List = [int(x) for x in input().split()]
	if n == 2 or m < n:
		print(-1)
	else:
		print(sum(List) * 2)
		for i in range(m - 1):
			print(i + 1, i + 2)
		print(m, 1)


import sys
input = sys.stdin.readline

def securityCost(n, m, a):
	if m < n:
		return None
	elif n == 2:
		return None
	return 2 * sum(a)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = securityCost(n, m, a)
	if ans is None:
		print(-1)
	else:
		print(ans)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, m) = rint()
	a = list(rint())
	if n == 2:
		print(-1)
		continue
	if m < n:
		print(-1)
		continue
	ai = [i for i in range(1, n + 1)]
	ai.sort(key=lambda e: a[e - 1])
	ans = 2 * sum(a) + (m - n) * (a[ai[0] - 1] + a[ai[1] - 1])
	print(ans)
	for i in range(m - n):
		print(ai[0], ai[1])
	for i in range(1, n + 1):
		print(i, i % n + 1)


def solve(n, m, cs):
	if m < n or n < 3:
		return (-1, None)
	(a, b) = (None, None)
	(a_ind, b_ind) = (None, None)
	for (i, c) in enumerate(cs, 1):
		if a is None or c < a:
			b = a
			b_ind = a_ind
			a = c
			a_ind = i
		elif b is None or c < b:
			b = c
			b_ind = i
	connections = [[i, j] for (i, j) in zip(range(1, n), range(2, n + 1))] + [[n, 1]]
	total = 2 * sum(cs)
	leftover_chains = m - n
	total += (a + b) * leftover_chains
	connections += [a_ind, b_ind] * leftover_chains
	return (total, connections)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	cs = [int(c) for c in input().split()]
	(total, connections) = solve(n, m, cs)
	print(total)
	if total != -1:
		for c in connections:
			print(*c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
		continue
	ans = 2 * sum(s)
	print(ans)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, recursion_limit, stack_size):
		setrecursionlimit(recursion_limit)
		threading.stack_size(stack_size)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(n, m) = [int(x) for x in R().split()]
			a = [int(x) for x in R().split()]
			if m < n or n == 2:
				ans.append('-1')
			else:
				ans.append(str(2 * sum(a)))
				for i in range(1, n):
					ans.append(str(i) + ' ' + str(i + 1))
				ans.append(str(n) + ' ' + '1')
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
threading.Thread(target=main).start()


t = int(input())
for T in range(t):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	arr = [int(i) for i in input().split()]
	sum = 0
	for i in range(n):
		sum += arr[i]
	if n != m or n < 3:
		print(-1)
	else:
		print(2 * sum)
		for i in range(n):
			if i != n - 1:
				print(i + 1, i + 2)
			else:
				print(i + 1, 1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n <= 2:
		print(-1)
		continue
	if m < n:
		print(-1)
		continue
	cost = 0
	edges = []
	for i in range(n):
		edges.append((i + 1, (i + 1) % n + 1))
		cost += 2 * a[i]
	s = sorted(range(n), key=lambda i: a[i])
	for i in range(m - n):
		edges.append((s[0] + 1, s[1] + 1))
		cost += a[s[0]] + a[s[1]]
	print(cost)
	for (u, v) in edges:
		print(u, v)


import sys
import math
import decimal
from collections import OrderedDict

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
for _ in range(iinput()):
	(n, m) = minput()
	a = listinput()
	if n > m or n == 2:
		print(-1)
	else:
		print(2 * sum(a))
		for i in range(m - 1):
			print(i + 1, i + 2)
		print(m, 1)


def read():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def solve(n, m, a):
	if m < n:
		return -1
	if n == 2:
		return -1
	total = 0
	pairs = []
	for i in range(n - 1):
		w = a[i] + a[i + 1]
		pairs.append((i + 1, i + 2, w))
		total += w
	w = a[-1] + a[0]
	pairs.append((n, 1, w))
	total += w
	min_pair = min(pairs, key=lambda p: p[2])
	for i in range(m - n):
		pairs.append(min_pair)
	return (total, pairs)
for i in range(int(input())):
	result = solve(*read())
	if result == -1:
		print(-1)
	else:
		print(result[0])
		for pair in result[1]:
			print(str(pair[0]) + ' ' + str(pair[1]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m <= 2 or m < n:
		print(-1)
	else:
		b = a.copy()
		b.sort()
		f = b[n - 1]
		s = b[n - 2]
		in1 = a.index(f)
		in2 = a.index(s)
		extra = m - n
		ans = 2 * sum(a)
		ans += extra * (f + s)
		print(ans)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(extra):
			print(in1 + 1, in2 + 1)


T = int(input().strip())
for _ in range(T):
	(n, m) = map(int, input().strip().split())
	w = [int(i) for (index, i) in enumerate(input().strip().split())]
	if n == 2:
		print(-1)
	elif m < n:
		print(-1)
	else:
		print(2 * sum(w))
		for i in range(2, n + 1):
			print(i - 1, i)
		print(n, 1)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	bs = 0
	for ele in l:
		bs += ele
	b = [ele for ele in l]
	l.sort()
	st = l[0]
	en = l[1]
	s1 = b.index(st)
	e1 = b.index(en)
	if m < n:
		print(-1)
	elif m == 2 and n == 2:
		print(-1)
	else:
		print(bs * 2 + (m - n) * (l[0] + l[1]))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for j in range(m - n):
			print(s1 + 1, en + 1)


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if n > m or n <= 2:
		print('-1')
		continue
	total = sum(arr)
	total *= 2
	total *= int(m / n)
	for i in range(0, m % n):
		total += arr[i] + arr[i + 1]
	print(total)
	node = 1
	for i in range(m):
		temp = node + 1
		if temp > n:
			temp = 1
		print(node, temp)
		node = temp


T = int(input())
for i in range(T):
	lst_mn = list(map(int, input().split()))
	lst_wei = list(map(int, input().split()))
	n = lst_mn[0]
	m = lst_mn[1]
	if n == 2:
		print(-1)
	elif m > n:
		lst_wei2 = lst_wei[:]
		min1 = min(lst_wei)
		p_min1 = lst_wei.index(min(lst_wei))
		del lst_wei2[p_min1]
		min2 = min(lst_wei2)
		p_min2 = lst_wei.index(min2)
		monoy = sum(lst_wei) * 2 + (min1 + min2) * (m - n)
		print(monoy)
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				print(i, j)
		for i in range(m - n):
			print(min1 + 1, min2 + 1)
	elif m == n:
		print(sum(lst_wei) * 2)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
	elif m < n:
		print(-1)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	sp = list(map(int, input().split()))
	if m < n or n < 3:
		print(-1)
	else:
		min1 = 100000
		min2 = 100000
		pos1 = 0
		pos2 = 0
		s = 0
		for i in range(n):
			s += sp[i]
			if sp[i] < min1:
				min1 = sp[i]
				pos1 = i + 1
			elif sp[i] < min2:
				min2 = sp[i]
				pos2 = i + 1
		print(2 * s + (m - n) * (min1 + min2))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m - n):
			print(pos1, pos2)


I = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, m) = I()
	s = 2 * sum(I())
	if n == m > 2:
		print(s)
		for i in range(1, n + 1):
			print(i, i % n + 1)
	else:
		print(-1)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, input().split())

def solve():
	(n, m) = mints()
	r = sum(mints()) * 2
	if m == n and n > 2:
		print(r)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
	else:
		print(-1)
for i in range(mint()):
	solve()


def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, m) = readIntArr()
		a = readIntArr()
		if n > 2 and m >= n:
			weights = []
			for (i, w) in enumerate(a):
				weights.append([w, i])
			weights.sort(key=lambda x: x[0])
			lo1 = weights[0][1] + 1
			lo2 = weights[1][1] + 1
			add = weights[0][0] + weights[1][0]
			c = 2 * sum(a)
			c += add * (m - n)
			allans.append([c])
			for i in range(1, n + 1):
				u = i
				v = i + 1
				if v > n:
					v -= n
				allans.append([u, v])
			for __ in range(m - n):
				allans.append([lo1, lo2])
		else:
			allans.append([-1])
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


for i in range(int(input())):
	(n, m) = (int(x) for x in input().split())
	a = [int(x) for x in input().split()]
	b = a.copy()
	a.sort()
	if m < n or n == 2:
		print(-1)
		continue
	cost = sum(a) * 2
	print(cost)
	for j in range(1, n):
		print(j, j + 1)
	print(n, 1)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		cost = sum(a) * 2
		(min1, min2) = (a[0], a[1])
		(ind1, ind2) = (0, 1)
		for i in range(n):
			if a[i] <= min1:
				min2 = min1
				ind2 = ind1
				min1 = a[i]
				ind1 = i
		diff = m - n
		cost = cost + (min1 + min2) * diff
		print(cost)
		for i in range(0, n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(diff):
			print(ind1 + 1, ind2 + 1)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
		continue
	ans = sum(a) * 2
	print(ans)
	for i in range(1, n + 1):
		if i == n:
			print(i, 1)
		else:
			print(i, i + 1)


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, m) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	if m < n or n == 2:
		print(-1)
	else:
		ans = 0
		for i in range(n):
			ans += arr[i] + arr[(i + 1) % n]
		print(ans)
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)


from sys import stdin

def rl():
	return [int(w) for w in stdin.readline().split()]
test = int(stdin.readline())
while test:
	test -= 1
	(n, m) = rl()
	a = list()
	a = rl()
	if n == 2:
		print(-1)
		continue
	if m < n:
		print(-1)
	else:
		sum = 0
		for x in a:
			sum += x
		sum *= 2
		print(sum)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)


def main():
	(n, m) = list(map(int, input().split()))
	costs = list(map(int, input().split()))
	if m < n:
		print(-1)
		return 0
	min1 = costs.index(min(costs))
	if n == 2:
		print(-1)
		return 0
	if min1 != 0:
		min2 = 0
	else:
		min2 = 1
	for i in range(n):
		if costs[i] < costs[min2] and i != min1:
			min2 = i
	t = sum(costs)
	print(2 * t + (costs[min1] + costs[min2]) * (m - n))
	for i in range(n):
		if i + 2 == n:
			print(i + 1, i + 2)
		else:
			print(i + 1, (i + 2) % n)
	for i in range(m - n):
		print(min1 + 1, min2 + 1)
	return 0
a = int(input())
for i in range(a):
	main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	a = sorted(range(len(lis)), key=lambda k: lis[k])
	if n <= 2:
		print('-1')
		continue
	if m < n:
		print('-1')
		continue
	else:
		ans = sum(lis) * 2
		m -= n
		ans += m * (lis[a[0]] + lis[a[1]])
	print(ans)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(m):
		print(a[0] + 1, a[1] + 1)


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


import collections
for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	elif m == n:
		print(2 * sum(a))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
	else:
		b = [(a[i], i + 1) for i in range(n)]
		b.sort()
		d = m - n
		ans = sum(a) + d * (b[0][0] + b[1][0])
		for i in range(d):
			print(b[0][1], b[1][1])
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)


from sys import stdin, stdout
t = int(stdin.readline())
while t != 0:
	t -= 1
	(n, m) = map(int, stdin.readline().split())
	L = list(map(int, stdin.readline().split()))
	if n >= 3 and m == n:
		s = 0
		for a in range(len(L)):
			s += 2 * L[a]
		print(s)
		length = len(L) - 1
		for a in range(len(L)):
			if a == length:
				print(length + 1, 1)
			else:
				print(a + 1, a + 2)
	else:
		print(-1)


import sys
import collections
import heapq
import math
input = sys.stdin.readline

def rints():
	return map(int, input().strip().split())

def rstr():
	return input().strip()

def rint():
	return int(input().strip())

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = rint()
for _ in range(t):
	(n, m) = rints()
	costs = rintas()
	costs.sort()
	if m < n or n == 2:
		print(-1)
	else:
		cost = 2 * sum(costs)
		d = m - n
		if d >= n:
			cost += cost * (d // n)
			d = d % n
		for i in range(1, d + 1):
			cost += costs[i] + costs[i - 1]
		print(cost)
		times = m // n
		while times > 0:
			i = 1
			while i < n:
				print(str(i), str(i + 1))
				i += 1
			print(str(i), '1')
			times -= 1
		d = m % n
		i = 1
		while i <= d:
			print(str(i), str(i + 1))
			i += 1


nCases = int(input())
while nCases > 0:
	nCases -= 1
	(nNodes, nEdges) = [int(x) for x in input().split()]
	weights = [int(x) for x in input().split()]
	if nEdges < nNodes:
		print(-1)
		continue
	if nEdges < 3:
		print(-1)
		continue
	weight = sum(weights) * 2
	print(weight)
	for i in range(1, nNodes):
		print(i, i + 1)
	print(nNodes, 1)


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber
t = ii()
for _ in range(t):
	(n, m) = mi()
	a = li()
	if n > m or n == 2:
		print(-1)
	else:
		ans = 2 * sum(a)
		mina = min(a)
		posmin = a.index(min(a))
		b = a.copy()
		b.sort()
		posmin1 = a.index(b[1])
		if posmin == posmin1:
			posmin1 = a.index(b[1], posmin + 1)
		ans += (mina + b[1]) * (m - n)
		print(ans)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m - n):
			print(posmin + 1, posmin1 + 1)


from sys import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	if n == 2 or k < n:
		print(-1)
	else:
		sm = 2 * sum(a)
		k -= n
		m1 = m2 = max(a) + 1
		g = h = -1
		for i in range(n):
			if a[i] < m1:
				m1 = a[i]
				g = i + 1
		a[g - 1] = max(a) + 2
		for i in range(n):
			if a[i] < m2:
				m2 = a[i]
				h = i + 1
		sm += (m1 + m2) * k
		print(sm)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(i + 2, 1)
		for i in range(k):
			print(g, h)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	w = l.copy()
	q = m
	if n > 2:
		if m >= n:
			c = 2 * sum(l)
			q -= n
			asd = min(l)
			w.remove(min(w))
			asd += min(w)
			c += q * asd
			print(c)
			for i in range(1, n):
				print(i, i + 1)
			print(n, 1)
			w = l.copy()
			z = w.index(min(w))
			w.remove(min(w))
			v = w.index(min(w))
			if z > v:
				z += 1
				v += 1
			else:
				z += 1
				v += 2
			for i in range(q):
				print(z, v)
		else:
			print(-1)
	else:
		print(-1)


from math import ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	if b < a or a < 3:
		print(-1)
	else:
		l = []
		mini = 1000000000.0
		index = [-1, -1]
		for n in range(a):
			l.append([n + 1, n + 2 if n + 2 <= a else 1])
			mi = arr[n] + arr[(n + 1) % a]
			if mi < mini:
				index[0] = n + 1
				index[1] = n + 2
				mini = mi
		l += [index] * (b - a)
		print(sum(arr) * 2 + mi * (b - a))
		for x in range(b):
			if x < a:
				print(*l[x])
			else:
				print(index[0], index[1])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	a = sorted(li)
	if m < n or n == 2:
		print(-1)
	else:
		print(2 * sum(a) + (a[1] + a[0]) * (m - n))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for j in range(m - n):
			print(li.index(a[0]) + 1, li.index(a[1]) + 1)


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	(a, b) = map(int, input().split())
	return (a, b)

def qw(n, r=2):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
t = 1
t = inp()
for tt in range(t):
	(n, m) = invr()
	a = inlt()
	ww = 0
	q = []
	if n <= m and n != 2:
		for i in range(n - 1):
			q.append([i + 1, i + 2])
			ww = ww + a[i] + a[i + 1]
		q.append([n, 1])
		ww = ww + a[n - 1] + a[0]
		w = len(q)
		b = sorted(a)
		qwqw = b[0] + b[1]
		qa = a.index(b[0])
		a[qa] = -1
		qa = qa + 1
		qb = a.index(b[1]) + 1
		for i in range(w, m):
			q.append([qa, qb])
			ww = ww + qwqw
		print(ww)
		for i in range(m):
			print(*q[i])
	else:
		print(-1)


from heapq import nsmallest
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if m < n:
		print(-1)
		continue
	if n == 2:
		print(-1)
		continue
	tmp = nsmallest(2, arr)
	d = []
	k1 = arr.index(tmp[0])
	if tmp[0] == tmp[1]:
		k2 = arr.index(tmp[1], k1 + 1, n)
	else:
		k2 = arr.index(tmp[1])
	sumi = 0
	for i in range(m):
		if i < n:
			sumi += arr[i] + arr[(i + 1) % n]
			d.append([i + 1, (i + 1) % n + 1])
		else:
			sumi += arr[k1] + arr[k2]
			d.append([k1 + 1, k2 + 1])
	print(sumi)
	for i in d:
		print(i[0], end=' ')
		print(i[1])


T = int(input())
for t in range(T):
	(N, M) = map(int, input().split())
	lst = list(map(int, input().split()))
	if M < N or N == 2:
		print(-1)
	else:
		tot = 2 * sum(lst)
		if N != M:
			var1 = lst.index(min(lst))
			temp = lst[var1]
			lst[var1] = 10000
			var2 = lst.index(min(lst))
			tot += (temp + lst[var2]) * (M - N)
		print(tot)
		for i in range(N):
			if i + 1 < N:
				print('{} {}'.format(i + 1, i + 2))
			else:
				print('{} {}'.format(i + 1, 1))
		if N != M:
			for i in range(M - N):
				print('{} {}'.format(var1 + 1, var2 + 1))


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	q = int(input())
	for _ in range(q):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		if n > m or n == 2:
			print(-1)
		else:
			ansv = 2 * sum(a)
			ans = [[k, k + 1] for k in range(1, n)]
			ans.append([n, 1])
			b = sorted([[a[k], k + 1] for k in range(n)])
			for k in range(m - n):
				ans.append([b[0][1], b[1][1]])
			print(ansv + (m - n) * (b[0][0] + b[1][0]))
			for e in ans:
				print(*e)
main()


t = int(input())
for o in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = list(sorted(a))
	min1 = a.index(d[0])
	min2 = a.index(d[1])
	if min1 == min2:
		min2 += 1
	res1 = []
	if n > k or n == 2:
		print(-1)
	else:
		for i in range(n):
			if i + 2 > n:
				res1.append(str(i + 1) + ' ' + str(1))
			else:
				res1.append(str(i + 1) + ' ' + str(i + 2))
		res = 2 * sum(a)
		while k > n:
			res1.append(str(min1 + 1) + ' ' + str(min2 + 1))
			res += d[0] + d[1]
			k -= 1
		print(res)
		for i in range(len(res1)):
			print(res1[i])


from heapq import nsmallest
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if n == 2 or m < n:
		print(-1)
		continue
	r = 0
	l = []
	for (i, _) in enumerate(a[:-1]):
		r += a[i] + a[i + 1]
		l.append(str(i + 1) + ' ' + str(i + 2))
		m -= 1
	r += a[0] + a[-1]
	l.append(str(len(a)) + ' 1')
	m -= 1
	(x, y) = nsmallest(2, a)
	if x == y:
		s = str(a.index(x) + 1) + ' ' + str(a.index(x, a.index(x) + 1, len(a)) + 1)
	else:
		s = str(a.index(x) + 1) + ' ' + str(a.index(y) + 1)
	r += (x + y) * m
	while m > 0:
		m -= 1
		l.append(s)
	print(r)
	for e in l:
		print(e)


tc = int(input())
for ii in range(tc):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
		continue
	ans = 0
	mn1 = float('inf')
	for i in range(n):
		ans += ar[i] * 2
		if ar[i] < mn1:
			save1 = i
			mn1 = ar[i]
	m -= n
	mn2 = float('inf')
	for i in range(n):
		if ar[i] < mn2 and i != save1:
			mn2 = ar[i]
			save2 = i
	ans += m * (mn1 + mn2)
	print(ans)
	for i in range(m):
		print(save1 + 1, save2 + 1)
	for i in range(n):
		print(i + 1, (i + 1) % n + 1)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	suma = 2 * sum(a[:])
	if n == 2 or n != m:
		print(-1)
	else:
		print(suma)
		for i in range(1, n + 1):
			if i == n:
				print(i, (i + 1) % n)
			else:
				print(i, i + 1)


g = ''
n = int(input())
for _ in range(n):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = sorted(a)
	f = b[0] + b[1]
	d = len(a)
	if m >= d and n > 2:
		c = 2 * sum(a) + f * (m - d)
		g += str(c) + '\n'
		for i in range(1, d):
			g += str(i) + ' ' + str(i + 1) + '\n'
		g += str(d) + ' 1\n'
		h = str(a.index(b[0]) + 1) + ' '
		a[a.index(b[0])] += 10001
		b = sorted(a)
		h += str(a.index(b[0]) + 1) + '\n'
		g += h * (m - d)
	else:
		g += '-1\n'
print(g)


t = int(input())
while t:
	t -= 1
	(n, m) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print('-1')
		continue
	i1 = i2 = 0
	m1 = m2 = float('inf')
	ans = 0
	res = []
	for i in range(n):
		res.append((i % n + 1, (i + 1) % n + 1))
		ans += a[i] + a[(i + 1) % n]
		if a[i] < m1:
			m2 = m1
			m1 = a[i]
			i2 = i1
			i1 = i + 1
		elif m2 > a[i]:
			m2 = a[i]
			i2 = i + 1
		m -= 1
	ans += m * (m1 + m2)
	for i in range(m):
		res.append((i1, i2))
	print(ans)
	for x in res:
		print(x[0], x[1])


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		suma = sum(a)
		answer = 2 * suma
		m -= n
		i = -1
		j = -1
		if min(a[1], a[0]) == a[0]:
			i = 0
			j = 1
		else:
			i = 1
			j = 0
		for k in range(2, n):
			if a[k] < a[i]:
				j = i
				i = k
			elif a[k] < a[j]:
				j = k
		answer += m * (a[i] + a[j])
		print(answer)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m):
			print(j + 1, i + 1)


from sys import stdin
import math

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, m) = [int(x) for x in inp().split()]
	ar = [int(x) for x in inp().split()]
	if m < n or n <= 2:
		print(-1)
	else:
		min1 = float('inf')
		min2 = float('inf')
		minpos1 = -1
		minpos2 = -1
		for i in range(n):
			if min(min2, ar[i]) < min2 and min(min2, ar[i]) >= min1:
				min2 = min(min2, ar[i])
				minpos2 = i + 1
			if min(min1, ar[i]) < min1:
				if min(min2, min1) < min2:
					min2 = min(min2, min1)
					minpos2 = minpos1
				min1 = min(min1, ar[i])
				minpos1 = i + 1
		print(2 * sum(ar) + (m - n) * (min1 + min2))
		for i in range(m):
			if i < n - 1:
				print(i + 1, end=' ')
				print(i + 2)
			elif i == n - 1:
				print(i + 1, end=' ')
				print(1)
			else:
				print(minpos1, end=' ')
				print(minpos2)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	if n == 2 or m < n:
		print(-1)
		continue
	ans = 0
	for i in range(1, n):
		ans += arr[i] + arr[i - 1]
	ans += arr[0] + arr[n - 1]
	print(ans)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	summ = sum(s)
	if n == m and n > 2:
		print(summ * 2)
		for i in range(n - 1):
			print(1 + i, 1 + i + 1)
		print(n, 1)
	else:
		print(-1)


import itertools
rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : map(int, rr().split())
T = rri()
for tc in range(T):
	(n, m) = rrm()
	a = list(rrm())
	ls = []
	c = 0
	if m - n < 0 or n == 2:
		print('-1')
	else:
		for i in itertools.cycle(range(n)):
			if i == n - 1:
				c += a[0] + a[n - 1]
				ls.append('{} {}'.format(n, 1))
			else:
				c += a[i] + a[i + 1]
				ls.append('{} {}'.format(i + 1, i + 2))
			m -= 1
			if m == 0:
				break
		print(c)
		for i in range(len(ls)):
			print(ls[i])


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if n == 2:
		print(-1)
	elif n > m:
		print(-1)
	else:
		print(2 * sum(a))
		for _ in range(0, n):
			print(_ + 1, (_ + 1) % n + 1)
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n <= 2 or m < n:
		print(-1)
	else:
		first = 1
		second = 2
		print(2 * sum(arr))
		while first <= n:
			print(first, second)
			first += 1
			second += 1
			if second > n:
				second = 1


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	if len(a) == 2 or len(a) > m:
		print(-1)
	else:
		largest = 0
		seclargest = 0
		lindex = 0
		sindex = 0
		for i in range(len(a)):
			if a[i] > largest:
				(largest, seclargest, lindex, sindex) = (a[i], largest, i, lindex)
			elif a[i] > seclargest:
				(seclargest, sindex) = (a[i], i)
		print(2 * sum(a) + (m - n) * (largest + seclargest))
		for i in range(len(a) - 1):
			print(i + 1, i + 2)
		print(len(a), 1)
		for i in range(m - len(a)):
			print(lindex + 1, sindex + 1)


import sys
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	if n == 2 or n > m:
		print(-1)
		continue
	if li[0] < li[1]:
		min1 = 0
		min2 = 1
	else:
		min1 = 1
		min2 = 0
	for i in range(2, n):
		if li[i] < li[min1]:
			min2 = min1
			min1 = i
		elif li[i] < li[min2]:
			min2 = i
	print(sum(li) * 2 + (m - n) * (li[min1] + li[min2]))
	for i in range(n):
		print(i + 1, (i + 1) % n + 1)
	for i in range(m - n):
		print(min1 + 1, min2 + 1)


test_case = int(input())
output = ''
for z in range(0, test_case):
	line = input().split()
	(n, m) = (int(line[0]), int(line[1]))
	wights = [int(x) for x in input().split()]
	if m < n or n == 2:
		output += '-1\n'
	else:
		total_cost = 0
		for x in wights:
			total_cost += 2 * x
		output += '%s\n' % total_cost
		for i in range(1, n):
			output += '%s %s\n' % (i, i + 1)
		output += '%s 1\n' % n
print(output[:-1])


T = int(input())
for _ in range(T):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	if m is not n or n == 2:
		print(-1)
	else:
		print(2 * sum(a))
		for i in range(1, n):
			print(str(i) + ' ' + str(i + 1))
		print(str(n) + ' ' + str(1))


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
for _ in range(iinput()):
	(n, m) = minput()
	if n > m or n < 3:
		_ = listinput()
		print(-1)
	else:
		print(2 * sum(listinput()))
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = []
	if m != n or n == 2:
		return print(-1)
	print(sum(a) * 2)
	for i in range(n):
		print(i + 1, (i + 1) % n + 1)
for _ in range(int(input())):
	solve()


import sys
from operator import itemgetter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, M) = MAP()
	A = LIST()
	A2 = []
	for (i, a) in enumerate(A):
		A2.append((i + 1, a))
	if N > M or N <= 2:
		print(-1)
		continue
	cost = sum(A) * 2
	edges = []
	for i in range(N):
		if i != N - 1:
			edges.append((i + 1, i + 2))
		else:
			edges.append((i + 1, i + 2 - N))
	M -= N
	A2.sort(key=itemgetter(1))
	cost += (A2[0][1] + A2[1][1]) * M
	for i in range(M):
		edges.append((A2[0][0], A2[1][0]))
	print(cost)
	for (a, b) in edges:
		print(a, b)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m) = LI()
		a = LI()
		if n < 3 or m < n:
			rr.append(-1)
		else:
			s = sum(a)
			rr.append(s * 2)
			for i in range(n):
				rr.append(JA([i + 1, (i + 1) % n + 1], ' '))
	return JA(rr, '\n')
print(main())


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		b.append([a[i], i])
	b.sort()
	M = b[0][0] + b[1][0]
	M1 = b[0][1]
	M2 = b[1][1]
	cost = sum(a) * 2
	money = []
	ans = []
	cost += M * (m - n)
	if m < n or n == 2:
		print(-1)
		continue
	print(cost)
	for i in range(n - 1):
		print(i + 1, i + 2)
	print(n, 1)
	if m - n > 0:
		for _ in range(m - n):
			print(M1 + 1, M2 + 1)


import sys

def merge(arr, l, m, r):
	n1 = m - l + 1
	n2 = r - m
	L = [0] * n1
	R = [0] * n2
	for i in range(n1):
		L[i] = arr[l + i]
	for j in range(n2):
		R[j] = arr[m + 1 + j]
	i = 0
	j = 0
	k = l
	while i < n1 and j < n2:
		if L[i] >= R[j]:
			arr[k] = R[j]
			j += 1
		else:
			arr[k] = L[i]
			i += 1
		k += 1
	while i < n1:
		arr[k] = L[i]
		k += 1
		i += 1
	while j < n2:
		arr[k] = R[j]
		k += 1
		j += 1

def mergeSort(arr, l, r):
	if l < r:
		m = l + (r - l) // 2
		mergeSort(arr, l, m)
		mergeSort(arr, m + 1, r)
		merge(arr, l, m, r)
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	array = [int(i) for i in input().split()]
	if m < n or n == 2:
		print(-1)
		continue
	array_initial = array[:]
	mergeSort(array, 0, n - 1)
	p = 1 + array_initial.index(array[0])
	q = 1 + array_initial.index(array[1])
	sys.stdout.write(str(2 * sum(array) + (m - n) * (array[0] + array[1])) + '\n')
	for i in range(m - n):
		sys.stdout.write('{one} {two}\n'.format(one=p, two=q))
	for i in range(n):
		sys.stdout.write('{one} {two}\n'.format(one=1 + i % n, two=1 + (i + 1) % n))


for _ in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = list(map(int, input().split()))
	a.sort()
	ans = -1
	if n == 2 or n > m:
		print(-1)
	else:
		ans = 2 * sum(a)
		d = m - n
		ans += d * (a[1] + a[0])
		print(ans)
		for i in range(d + 1):
			print('1 2')
		x = 2
		y = 3
		for j in range(n - 1):
			print(x, y)
			x += 1
			if x > n:
				x = 1
			y += 1
			if y > n:
				y = 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	p = [v for v in range(1, n + 1)]
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		ans = [2 * _ for _ in l]
		print(sum(ans))
		for i in range(0, n - 1):
			print(p[i], p[i + 1])
		print(p[n - 1], p[0])


q = int(input())
m = []
for i in range(q):
	m1 = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1.append(a)
	m1.append(b)
	m.append(m1)
for i in range(q):
	u = m[i][0][0]
	v = m[i][0][1]
	if u > v or u <= 2:
		print(-1)
	else:
		mcopy = m[i][1].copy()
		m[i][1].sort()
		index1 = mcopy.index(m[i][1][0])
		index2 = mcopy.index(m[i][1][1])
		n = v - u
		print(sum(m[i][1]) * 2 + (m[i][1][0] + m[i][1][1]) * n)
		for x in range(1, u + 1):
			if x != u:
				print(x, x + 1)
			else:
				print(x, 1)
		for z in range(n):
			print(index1 + 1, index2 + 1)


r = range
input = list(open(0))[::-1].pop
for _ in r(int(input())):
	(n, m) = map(int, input().split())
	m -= n
	(*a,) = map(int, input().split())
	if n < 3 or m < 0:
		print(-1)
		continue
	(x, y, *_) = sorted(r(n), key=lambda x: a[x])
	print(sum(a) * 2 + (a[x] + a[y]) * m)
	for (i, j) in zip(r(n), r(1, n + 1)):
		print(i + 1, j % n + 1)
	for _ in r(m):
		print(x + 1, y + 1)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	if m >= n and n != 2:
		ans = 2 * sum(w)
		m1 = min(w)
		i1 = w.index(m1)
		w.remove(m1)
		m2 = min(w)
		i2 = w.index(m2)
		if i2 >= i1:
			i2 += 1
		for i in range(m - n):
			ans += m1 + m2
		print(ans)
		for i in range(m - n):
			print(i1 + 1, i2 + 1)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
	else:
		print(-1)


from sys import stdin
cas = int(stdin.readline().strip())
for caso in range(cas):
	(n, m) = map(int, stdin.readline().strip().split())
	s = list(map(int, stdin.readline().strip().split()))
	s.sort()
	if m < n or n == 2:
		print(-1)
	else:
		print(sum(s) * 2)
		for i in range(n):
			print(1 + i % n, 1 + (i + 1) % n)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if n == 2:
		print(-1)
	elif n >= 3:
		if m < n:
			print(-1)
		elif m >= n:
			min1 = min(a)
			z = a.index(min1)
			a[z] = 10000000
			min2 = min(a)
			a[z] = min1
			print(sum(a) * 2 + (m - n) * (min1 + min2))
			for i in range(n - 1):
				print(i + 1, i + 2)
			print(n, 1)
			for i in range(m - n):
				print(min1, min2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if m < n or n == 2:
		print(-1)
	else:
		total = 0
		ans = []
		for i in range(n):
			total += arr[i] + arr[(i + 1) % n]
			ans.append((i + 1, (i + 1) % n + 1))
		for i in range(m - n):
			total += arr[0] + arr[1]
			ans.append((1, 2))
		print(total)
		for ele in ans:
			print(*ele)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
		continue
	cost = 0
	ans = []
	for i in range(1, n + 1):
		if i == n:
			ans.append([n, 1])
			cost += a[n - 1] + a[0]
			break
		cost += a[i - 1] + a[i]
		ans.append([i, i + 1])
	aa = []
	for k in range(n):
		aa.append([a[k], k])
	aa.sort()
	ele1 = aa[0]
	ele2 = aa[1]
	for g in range(m - n):
		ans.append([ele1[1] + 1, ele2[1] + 1])
		cost += ele2[0] + ele1[0]
	print(cost)
	for i in ans:
		print(i[0], i[1])


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	Query.append((N, M, A))
for (N, M, A) in Query:
	if N != M or N == 2:
		print(-1)
	else:
		print(2 * sum(A))
		for i in range(M - 1):
			print(i + 1, i + 2)
		print(M, 1)


def main():
	global visited, adj, sets
	(n, m) = get_list()
	li = get_list()
	if n == 2 or m < n:
		print(-1)
	else:
		m1 = m2 = 10 ** 10
		i1 = i2 = 0
		for (ind, i) in enumerate(li):
			if i <= m1:
				m2 = m1
				i2 = i1
				m1 = i
				i1 = ind
			elif i < m2:
				m2 = i
				i2 = ind
		print(2 * sum(li) + (m - n) * (m1 + m2))
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)
		for i in range(m - n):
			print(i1 + 1, i2 + 1)
import sys
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	cost = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		total = 2 * sum(cost)
		q = cost.index(min(cost))
		pa = cost[q]
		cost[q] = 1000000
		p = cost.index(min(cost))
		ra = cost[p]
		op = m - n
		print(total + op * (pa + ra))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m - n * (n - 1) // 2):
			print(q + 1, p + 1)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	(n, m) = (l[0], l[1])
	l = list(map(int, input().split()))
	if m < n:
		print(-1)
		continue
	elif n == 2:
		print(-1)
	else:
		print(2 * sum(l))
		for i in range(1, n + 1):
			if i == n:
				print(n, 1)
			else:
				print(i, i + 1)


def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problem1():
	t = inp(int)
	for _ in range(t):
		(a, b) = inp(int)
		delta = abs(b - a)
		res = delta // 5
		delta = delta % 5
		res += delta // 2
		delta = delta % 2
		res += delta
		print(res)

def problem2():
	t = inp(int)
	for _ in range(t):
		(n, m) = inp(int)
		a = inp(int, strip=False)
		if n == 2 or m < n:
			print(-1)
		else:
			a = sorted(a)
			res = 2 * sum(a) + (a[0] + a[1]) * (m - n)
			print(res)
			for i in range(n):
				print(i + 1, (i + 1) % n + 1)
			for i in range(m - n):
				print(1, 2)

def problem3():
	pass

def problem4():
	pass

def problem5():
	pass
problem2()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	v = list(map(int, input().split()))
	v.sort()
	b = sorted(enumerate(v), key=lambda x: x[1])
	if m < n or n == 2:
		print(-1)
		continue
	res = 2 * sum(v) + (v[0] + v[1]) * (m - n)
	print(res)
	for i in range(n - 1):
		print(str(i + 1) + ' ' + str(i + 2))
	print(str(n) + ' ' + str(1))
	for i in range(m - n):
		print(str(b[0]) + ' ' + str(b[1]))


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	(a, b) = map(int, input().split())
	return (a, b)
t = 1
t = inp()
for tt in range(t):
	(n, m) = invr()
	a = inlt()
	ww = 0
	q = []
	if n == m and n != 2:
		for i in range(n - 1):
			q.append([i + 1, i + 2])
			ww = ww + a[i] + a[i + 1]
		q.append([n, 1])
		ww = ww + a[n - 1] + a[0]
		print(ww)
		for i in range(len(q)):
			print(*q[i])
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if m != n or n < 3:
		print(-1)
	else:
		print(2 * sum(l))
		for k in range(n):
			print(k + 1, (k + 1) % n + 1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	lst = list(map(int, input().split()))
	if a == 2:
		print(-1)
	elif a >= 3:
		if b < a:
			print(-1)
			continue
		elif a == b:
			print(2 * sum(lst))
			for c in range(1, a):
				print(c, c + 1)
			print(a, 1)


mod = 10 ** 9 + 7
import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def main():
	t = inin()
	for _ in range(t):
		(n, p) = cin()
		a = ain()
		if p < n or n == 2:
			print(-1)
			continue
		else:
			b = []
			for i in range(n):
				b.append((a[i], i))
			b.sort()
			jj = b[0][0]
			j = b[0][1]
			kk = b[1][0]
			k = b[1][1]
			x = sum(a) * 2
			y = jj + kk
			y = y * (p - n)
			print(x + y)
			for i in range(n - 1):
				print(i + 1, i + 2)
			print(n, 1)
			for i in range(p - n):
				print(j + 1, k + 1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		arr = list(enumerate(arr, start=1))
		sorted(arr, key=lambda arr: arr[1])
		cost = 0
		for i in range(n):
			cost += arr[i][1] * 2
		for j in range(abs(n - m)):
			cost += arr[j][1] * 2
		print(cost)
		for i in range(n + abs(n - m)):
			print(arr[i % n][0], arr[(i + 1) % n][0])


T = int(input())
for _ in range(T):
	(n, m) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	if m < n:
		print(-1)
		continue
	if n == 2:
		print(-1)
		continue
	print(2 * sum(A) + (m - n) * min(A))
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)


q = int(input())
for rwre in range(q):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if m < n:
		print(-1)
	else:
		ll = [[l[i], i + 1] for i in range(n)]
		ll.sort()
		l.sort()
		suma = 0
		if n == 2:
			print(-1)
		else:
			for i in range(n):
				suma += l[i - 1] + l[i]
			s1 = ll[0][1]
			s2 = ll[1][1]
			print(suma + (m - n) * (ll[0][0] + ll[1][0]))
			for i in range(n - 1):
				print(i + 1, i + 2)
			print(n, 1)
			a = n
			while a < m:
				print(s1, s2)
				a += 1


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
		continue
	ans = 0
	mina = min(a)
	mina2 = 0
	(idx1, idx2) = (-1, -1)
	if a.count(mina) > 1:
		mina2 = mina
		for i in range(n):
			if a[i] == mina:
				if idx1 == -1:
					idx1 = i + 1
				else:
					idx2 = i + 1
					break
	else:
		mina2 = 9999999999
		for i in range(n):
			if a[i] == mina:
				idx1 = i + 1
				continue
			if mina2 > a[i]:
				mina2 = a[i]
				idx2 = i + 1
	num = m - n
	v = []
	while num:
		ans += a[idx2 - 1] + a[idx1 - 1]
		num -= 1
	for i in range(n):
		if i == n - 1:
			v.append([n, 1])
			continue
		v.append([i + 1, i + 2])
	for i in range(n):
		ans += a[v[i][0] - 1] + a[v[i][1] - 1]
	print(ans)
	for i in range(n):
		print(v[i][0], v[i][1])


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = sorted(a)
	if n > m or n == 2:
		print(-1)
	else:
		c = sum(a) * 2
		o1 = a.index(b[0]) + 1
		a[a.index(b[0])] = 1000000
		o2 = a.index(b[1]) + 1
		c += (o1 + o2) * (m - n)
		print(c)
		for i in range(m - n):
			print(o1, o2)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, cns) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	if n == 2:
		print(-1)
		continue
	mn = float('inf')
	p1 = p2 = 0
	if cns < n:
		print(-1)
		continue
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] + a[j] < mn:
				mn = a[i] + a[j]
				p1 = i
				p2 = j
	print(2 * sum(a) + mn * (n - cns))
	for i in range(1, n + 1):
		print(i, i + 1 if i + 1 != n + 1 else 1)
	for i in range(n - cns):
		print(p1 + 1, p2 + 2)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	weights = list(map(int, input().split()))
	temp = sorted(weights)
	if n == 2 or m < n:
		print(-1)
	else:
		cost = 2 * sum(weights)
		print(cost)
		for i in range(1, n):
			print(f'{i} {i + 1}')
		print(f'{n} {1}')


for nt in range(int(input())):
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	if n == 2:
		print(-1)
		continue
	a = sorted(f)
	if n == m:
		print(2 * sum(a))
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		continue
	if n > m:
		print(-1)
		continue
	print(2 * sum(a) * ((a[0] + a[1]) * (m - n)))
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	(x1, x2) = (f.index(a[0]), f.index(a[1]))
	for i in range(m - n):
		print(x1 + 1, x2 + 1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	aa = list(map(int, input().split()))
	if m < n or n == 1 or n == 2:
		print(-1)
	else:
		a = [(aa[i], i) for i in range(n)]
		a = sorted(a)
		ans = sum(aa) * 2
		m -= n
		ans += m * (a[0][0] + a[1][0])
		print(ans)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
		for i in range(m):
			print(a[0][1] + 1, a[1][1] + 1)


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n != m or n == 2:
		print(-1)
		return
	c = 2 * sum(a)
	print(c)
	for i in range(n):
		if i != n - 1:
			print(i + 1, i + 2)
		else:
			print(n, 1)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		print(sum(A) * 2)
		for i in range(n):
			print(i + 1, (i + 1) % n + 1)


tests = int(input())
for _ in range(tests):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr = arr + [float('inf')]
	if m < n or n == 2:
		print(-1)
	else:
		result = []
		summ = 0
		for i in range(len(arr) - 1):
			if i == len(arr) - 2:
				if arr[i + 1] == float('inf'):
					result.append([i + 1, 1])
					summ += arr[i] + arr[0]
			else:
				result.append([i + 1, i + 2])
				summ += arr[i] + arr[i + 1]
		print(summ)
		for i in result:
			print(i[0], i[1])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
		continue
	s = 0
	(m1, m2) = (a[0], 10 ** 5)
	(inx1, inx2) = (0, 0)
	ans = []
	for i in range(n):
		if a[i] < m1:
			m2 = m1
			m1 = a[i]
			inx2 = inx1
			inx1 = i
		elif a[i] < m2:
			m2 = a[i]
			inx2 = i
		s += a[i] + a[(i + 1) % n]
		ans.append((i + 1, (i + 1) % n + 1))
		m -= 1
	while m:
		ans.append((inx1 + 1, inx2 + 1))
		s += a[inx1] + a[inx2]
		m -= 1
	print(s)
	for (i, j) in ans:
		print(i, j)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	cost = 0
	c = 0
	if n == 2 or m < n:
		print(-1)
	else:
		for i in range(n - 1):
			cost += a[i] + a[i + 1]
			c += 1
		cost += a[0] + a[n - 1]
		c += 1
		temp = [i for i in range(n)]
		xyz = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
		cc = c
		while c < m:
			c += 1
			cost += a[0] + a[1]
		print(cost)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		while cc < m:
			print(temp[0] + 1, temp[1] + 1)
			cc += 1


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	qwer = 0
	zxc = 0
	if n == 2 or m < n:
		print(-1)
	else:
		for i in range(n - 1):
			qwer += a[i] + a[i + 1]
			zxc += 1
		qwer += a[0] + a[n - 1]
		zxc += 1
		temp = [i for i in range(n)]
		zxczxc = zxc
		print(qwer)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		while zxczxc < m:
			print(temp[0] + 1, temp[1] + 1)
			zxczxc += 1


class cep:

	def __init__(self, num, i):
		self.self = num
		self.i = i

def s(a):
	return a.self
q = int(input())
for _ in range(q):
	(w, e) = map(int, input().split())
	r = list(map(int, input().split()))
	if e < max(3, w):
		print(-1)
	else:
		ans = sum(r) * 2
		e -= w
		for i in range(w):
			r[i] = cep(r[i], i + 1)
		r.sort(key=s)
		ans += e * (r[0].self + r[1].self)
		print(ans)
		for i in range(w):
			print(i + 1, (i + 1) % w + 1)
		for i in range(e):
			print(r[0].i, r[1].i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	ls = list(map(int, input().strip().split()))
	if m < n or n == 2:
		print('-1')
	else:
		mini = min(ls)
		secmini = 100000
		first_ind = ls.index(mini)
		sec_ind = -1
		for (ind, val) in enumerate(ls):
			if val < secmini and ind != first_ind:
				secmini = val
				sec_ind = ind
		temp = n - 1
		m -= n
		cost = sum(ls) * 2 + (mini + secmini) * m
		print(cost)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, '1')
		for _ in range(m):
			print(first_ind + 1, sec_ind + 1)


t = int(input())
for i in range(t):
	ins = list(map(int, input().split()))
	n = ins[0]
	m = ins[1]
	weights = list(map(int, input().split()))
	if n == 2 or m != n:
		print(-1)
		continue
	print(sum(weights) * 2)
	for j in range(1, n + 1):
		if j == n:
			print(j, end=' ')
			print(1)
		else:
			print(j, end=' ')
			print(j + 1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
	else:
		s = sum(a)
		for i in range(n):
			a[i] = [a[i], i + 1]
		a.sort()
		print(2 * s + (m - n) * (a[0][0] + a[1][0]))
		for i in range(1, n + 1):
			print(i, 1 + i % n)
		for i in range(m - n):
			print(a[0][1], a[1][1])


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, m) = [int(item) for item in input().split()]
	cost = [int(item) for item in input().split()]
	if m < n:
		print(-1)
		continue
	if n <= 2:
		print(-1)
		continue
	costid = []
	ans_cost = 0
	for (i, item) in enumerate(cost):
		costid.append((item, i))
		ans_cost += item
	costid.sort()
	ans_cost *= 2
	ans_cost += (m - n) * (costid[0][0] + costid[1][0])
	ans_edge = []
	print(ans_cost)
	for i in range(n):
		print(i + 1, (i + 1) % n + 1)
	for i in range(m - n):
		print(costid[0][1] + 1, costid[1][1] + 1)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if m < n or n <= 2:
		print(-1)
		continue
	print(sum(a) * 2)
	for i in range(n - 1):
		print(i + 1, i + 2)
	print(n, 1)