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

Source: codeforces | Difficulty: EASY
Tags: Graph algorithms

Implementation


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


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = [0] + list(map(int, input().split()))
	b = [[-1, i] for i in range(n + 1)]
	if m < n or n == 2:
		print(-1)
	else:
		for i in range(n + 1):
			b[i][0] = a[i]
		b.sort()
		ans = 0
		pr = []
		ind1 = b[1][1]
		ind2 = b[2][1]
		ind3 = b[3][1]
		ans = 0
		ans = 2 * sum(a)
		pr.append([1, n])
		for i in range(1, n):
			pr.append([i, i + 1])
		for i in range(m - n):
			pr.append([ind2, ind1])
			ans += a[ind2] + a[ind1]
		print(ans)
		for i in pr:
			print(*i)


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 collections import *
from functools import reduce
import sys
input = sys.stdin.readline

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())
for _ in range(val()):
	(n, m) = li()
	a = li()
	if n == 2:
		print(-1)
		continue
	for i in range(n):
		a[i] = [a[i], i]
	a.sort(key=lambda x: x[0])
	ans = []
	d = defaultdict(set)
	tot = 0
	for i in range(n):
		j = (i + 1) % n
		tot += a[i][0] + a[j][0]
		d[i].add(j)
		d[j].add(i)
		m -= 1
	if m < 0:
		print(-1)
		continue
	anset = set()
	for i in d:
		for j in d[i]:
			anset.add(tuple(sorted([a[i][1], a[j][1]])))
	while m:
		tot += a[0][0] + a[1][0]
		ans.append((a[0][1], a[1][1]))
		m -= 1
	print(tot)
	for i in anset:
		print(i[0] + 1, i[1] + 1)
	for i in ans:
		print(i[0] + 1, i[1] + 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())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
	else:
		print(sum(a) * 2)
		print(1, m)
		res = [i for i in range(1, m + 1)]
		for i in range(m - 1):
			print(res[i], res[i + 1])


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)


from collections import defaultdict as dd
t = int(input())
for i in range(t):
	m1 = dd(int)
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		m1[i + 1] = a[i]
	temp = list(zip(m1.keys(), m1.values()))
	temp = sorted(temp, key=lambda x: x[1])
	res = 0
	a.sort()
	if n == 2:
		print(-1)
		continue
	if m < n:
		print(-1)
		continue
	else:
		for i in range(n - 1):
			res += a[i] + a[i + 1]
	print(res + a[0] + a[-1])
	for i in range(n - 1):
		print(temp[i][0], ' ', temp[i + 1][0])
	print(temp[-1][0], ' ', temp[0][0])


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, math
MOD = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a = [(a[i], i + 1) for i in range(n)]
	a.sort()
	if n == 2 or m < n:
		print(-1)
		continue
	(total, ans) = (0, [])
	while len(a) > m:
		ans.append((a[0][1], a[-1][1]))
		ans.append((a[1][1], a[-1][1]))
		total += a[0][0] + a[-1][0]
		total += a[1][0] + a[-1][0]
		m -= 2
		a.pop()
	for i in range(len(a)):
		ans.append((a[i - 1][1], a[i][1]))
		total += a[i - 1][0] + a[i][0]
		m -= 1
	while m > 0:
		ans.append((a[0][1], a[1][1]))
		total += a[0][0] + a[1][0]
		m -= 1
	print(total)
	for chain in ans:
		print(*chain)


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)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')

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

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = array()
	cost = 0
	ans = []
	for i in range(1, n):
		ans.append((i, i + 1))
	ans.append((1, n))
	if n == 2:
		print(-1)
	elif k < len(ans):
		print(-1)
	else:
		for i in ans:
			cost += a[i[0] - 1] + a[i[1] - 1]
		print(cost)
		for i in ans:
			print(*i)


n = int(input())
import itertools
for i in range(n):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n != m:
		print(-1)
		continue
	if n == 2 and m == 2:
		print(-1)
		continue
	cost = 0
	c = []
	for i in range(n):
		x = [a[-i], a[i]]
		c.append(x)
	for i in c:
		cost += sum(i)
	print(cost)
	for i in range(1, n):
		print(i, i + 1)
	print(1, n)


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	l = input().split()
	li = []
	for i in range(n):
		li.append((int(l[i]), i))
	if n == 2:
		print(-1)
	elif n > m:
		print(-1)
	else:
		li.sort()
		min1 = li[0]
		min2 = li[1]
		suma = 0
		for i in range(n):
			suma += li[i][0]
		print(2 * suma + (m - n) * (min1[0] + min2[0]))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(1, n)
		for i in range(m - n):
			print(min1[1] + 1, min2[1] + 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)


t = int(input())
resAr = []
for z in range(t):
	(n, m) = [int(i) for i in input().split()]
	prices = [int(i) for i in input().split()]
	if m < n or n == 2:
		resAr.append([-1])
	else:
		rA = [0]
		d = {}
		for i in prices:
			d[i] = []
		for i in range(len(prices)):
			d[prices[i]].append(i)
		prices.sort()
		cost = 0
		lA = []
		k = list(d.keys())
		k.sort()
		for i in k:
			for j in d[i]:
				lA.append(j + 1)
		if n != 4:
			for i in range(len(prices) - 1):
				cost += prices[i] + prices[i + 1]
			cost += prices[0] + prices[len(prices) - 1]
			for i in range(len(lA) - 1):
				rA.append((lA[i], lA[i + 1]))
			rA.append((lA[0], lA[len(lA) - 1]))
		else:
			cost = prices[0] * 2 + prices[1] * 2 + prices[2] * 2 + prices[3] * 2
			for i in range(2, len(lA)):
				rA.append((lA[i], lA[0]))
				rA.append((lA[i], lA[1]))
		rA[0] = cost
		resAr.append(rA)
for i in resAr:
	print(i[0])
	for j in range(1, len(i)):
		print(i[j][0], i[j][1])


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

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

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

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

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

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

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 998244353
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		[n, m] = inlt()
		a_dash = inlt()
		a = []
		for i in range(len(a_dash)):
			a.append([a_dash[i], i + 1])
		a.sort()
		if n == 2:
			print(-1)
			continue
		chain = 0
		ans = 0
		if m < n:
			print(-1)
		elif m == n:
			print(2 * sum(a_dash))
			for i in range(n):
				pr_list([a[i % n][1], a[(i + 1) % n][1]])
		else:
			print(2 * sum(a_dash) + (m - n) * (a[0][0] + a[1][0]))
			for i in range(n):
				pr_list([a[i % n][1], a[(i + 1) % n][1]])
			for i in range(n, m):
				pr_list([a[0][1], a[1][1]])
main()


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


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()


import math
t = int(input())
for kkk in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	aCopy = sorted(a)
	ans = sum(a) * 2
	m -= n
	if m < 0 or n == 2:
		print(-1)
		continue
	ans += m * (aCopy[0] + aCopy[1])
	print(ans)
	for i in range(len(a) - 1):
		print(i + 1, i + 2)
	print(1, len(a))
	while m > 0:
		m -= 1
		minn = min(a)
		min2 = math.inf
		ind2 = 0
		ind1 = 0
		f = True
		for i in range(len(a)):
			if a[i] < min2 and (a[i] != minn or not f):
				min2 = a[i]
				ind2 = i + 1
			if a[i] == minn and f:
				ind1 = i + 1
				f = False
		print(ind1, ind2)


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


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])


t = int(input())
for j in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	cos = list()
	for i in range(len(a)):
		cos.append([a[i], i + 1])
	cos.sort()
	if m < n:
		print(-1)
		continue
	if n == 2:
		print(-1)
		continue
	ans = list()
	total = 0
	if m == n:
		for i in range(m - 1):
			ans.append([i + 1, i + 2])
		ans.append([1, m])
		total = 2 * sum(a)
	else:
		i = 0
		while m > 0 and n - 2 * i - 1 >= 3:
			ans.append([cos[i][1], cos[n - i - 1][1]])
			m -= 1
			total += cos[i][0] + cos[n - i - 1][0]
			ans.append([cos[i][1], cos[n - i - 2][1]])
			ans.append([cos[i + 1][1], cos[n - i - 1][1]])
			m -= 2
			total += cos[i][0] + cos[n - i - 2][0] + cos[i + 1][0] + cos[n - i - 1][0]
			ans.append([cos[i + 1][1], cos[n - i - 2][1]])
			total += cos[i + 1][0] + cos[n - i - 2][0]
			m -= 1
			i += 2
		if n - 2 * i - 1 == 2:
			ans.append([cos[i][1], cos[i + 1][1]])
			ans.append([cos[i + 1][1], cos[i + 2][1]])
			ans.append([cos[i + 2][1], cos[i][1]])
			total += 2 * (cos[i][0] + cos[i + 1][0] + cos[i + 2][0])
			m -= 3
		elif n - 2 * i - 1 == 1:
			ans.append([cos[i][1], cos[i + 1][1]])
			ans.append([cos[i][1], cos[0][1]])
			ans.append([cos[i + 1][1], cos[0][1]])
			total += 2 * (cos[i][0] + cos[i + 1][0] + cos[0][0])
			m -= 3
		else:
			ans.append([cos[i][1], cos[0][1]])
			ans.append([cos[i][1], cos[1][1]])
			total += cos[i][0] + cos[1][0] + cos[0][0] + cos[i][0]
			m -= 2
		if m > 0:
			for k in range(m):
				ans.append([cos[0][1], cos[1][1]])
				total += cos[0][0] + cos[1][0]
	print(total)
	for i in ans:
		print(*i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	cost = 0
	cost += 2 * sum(a)
	if m < n or n == 2:
		print(-1)
	else:
		x = min(a)
		first = a.index(x)
		a.pop(first)
		y = min(a)
		second = a.index(y)
		if second >= first:
			second += 1
		cost += (m - n) * (x + y)
		print(cost)
		for i in range(n - 1):
			print(i + 1, end=' ')
			print(i + 2)
		print('1 ' + str(n))
		for i in range(m - n):
			print(first + 1, end=' ')
			print(second + 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)


import sys
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	val = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
	else:
		l = val[:]
		l.sort()
		total = 2 * sum(l) + (m - n) * (l[0] + l[1])
		print(total)
		for j in range(1, n):
			print(j, j + 1)
		print(1, n)
		for j in range(m - n):
			print(val.index(l[0] + 1), val.index(l[1] + 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])


from operator import itemgetter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = sorted(zip(map(int, input().split()), range(1, n + 1)))
	if n == 2 or n > m:
		print(-1)
	else:
		ans = sum(map(itemgetter(0), a)) * 2
		ans += (a[0][0] + a[1][0]) * (m - n)
		print(ans)
		print(a[0][1], a[-1][1])
		for i in range(n - 1):
			print(a[i][1], a[i + 1][1])
		for i in range(n, m):
			print(a[0][1], a[1][1])


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)


t = int(input())
for i in range(t):
	s = input()
	n = int(s.split(' ')[0])
	m = int(s.split(' ')[1])
	s = input()
	w = s.split(' ')
	w = [int(word) for word in w]
	if m < n or n < 3:
		print('-1')
	else:
		w = sorted(w)
		cost = 0
		for i in range(n):
			cost += w[i] + w[(i + 1) % n]
		m = m - n
		if m > 0:
			cost += m * (w[0] + w[1])
		print(cost)
		for i in range(1, n + 1):
			node2 = (i + 1) % (n + 1)
			if node2 == 0:
				node2 = 1
			print(str(i), ' ', str(node2))


import sys
from collections import defaultdict
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	l = list(map(int, sys.stdin.readline().split()))
	for i in range(n):
		l[i] = [l[i], i + 1]
	l.sort()
	if n <= 2 or m < n:
		print(-1)
	else:
		s = 0
		for i in range(n):
			s += l[i][0]
		print(2 * s + (m - n) * (l[0][0] + l[1][0]))
		for i in range(n - 1):
			print(l[i][1], l[i + 1][1])
		print(l[n - 1][1], l[0][1])
		for i in range(m - n):
			print(l[0][1], l[1][1])


import operator
t = int(input())
for ti in range(t):
	try:
		(n, m) = input().split()
		n = int(n)
		m = int(m)
		a = input().split()
		wtdict = {}
		for j in range(n):
			a[j] = int(a[j])
			wtdict[j + 1] = a[j]
		sorted_wts = sorted(wtdict.items(), key=operator.itemgetter(1))
		anslist = []
		for w in range(n - 1):
			anslist.append((sorted_wts[w], sorted_wts[w + 1]))
		anslist.append((sorted_wts[n - 1], sorted_wts[0]))
		if m < n or n == 2:
			raise Exception
		elif m < 2 * n - 3:
			r = m - n
			for o in range(r):
				anslist.remove((sorted_wts[n - o - 2], sorted_wts[n - o - 1]))
				anslist.append((sorted_wts[n - o - 1], sorted_wts[1]))
				anslist.append((sorted_wts[n - o - 2], sorted_wts[0]))
			cost = 0
			for h in anslist:
				cost += h[0][1] + h[1][1]
			print(cost)
			for h in anslist:
				print(h[0][0], h[1][0])
		else:
			anslist2 = []
			anslist2.append((sorted_wts[0], sorted_wts[1]))
			for g in range(2, n):
				anslist2.append((sorted_wts[g], sorted_wts[0]))
				anslist2.append((sorted_wts[g], sorted_wts[1]))
			f = m - 2 * n + 3
			for e in range(f):
				anslist2.append((sorted_wts[0], sorted_wts[1]))
			cost = 0
			for h in anslist2:
				cost += h[0][1] + h[1][1]
			print(cost)
			for h in anslist2:
				print(h[0][0], h[1][0])
	except:
		print('-1')


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


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)


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


import collections
import functools
import heapq
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
	else:
		print(sum(arr) * 2)
		for j in range(1, m):
			print(j, j + 1)
		print(1, n)


q = int(input())
for t in range(q):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = []
	an = 0
	b = []
	for i in range(n - 1):
		ans.append([i + 1, i + 2])
		an += a[i] + a[i + 1]
		b.append([a[i], i + 1])
	ans.append([1, n])
	an += a[0] + a[n - 1]
	b.append([a[n - 1], n])
	b.sort()
	if len(ans) > m or n == 2:
		print(-1)
	else:
		for i in range(m - len(ans)):
			ans.append([b[0][1], b[1][1]])
			an += b[0][0] + b[1][0]
		print(an)
		for i in range(len(ans)):
			print(*ans[i])


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)


from math import inf
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if n == 2:
		print(-1)
	elif m < n:
		print(-1)
	else:
		print(2 * sum(a))
		for i in range(1, n):
			print(i, i + 1)
		else:
			print(1, n)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(((val, idx + 1) for (idx, val) in enumerate(map(int, input().split()))))
	a.sort()
	(val, idx) = list(zip(*a))
	if m < n or m > n + n * (n - 3) // 2:
		print(-1)
	else:
		s = sum(val) * 2
		l = [(idx[-1], idx[0])]
		for i in range(n - 1):
			l.append((idx[i], idx[i + 1]))
		(i, j) = (0, 2)
		for i in range(m - n):
			s += val[i] + val[j]
			l.append((idx[i], idx[j]))
			j += 1
			if j == n:
				i += 1
				j += i + 2
		print(s)
		for i in l:
			print(*i)


for _ in range(int(input())):
	(fr, ch) = map(int, input().split())
	arr = list(map(int, input().split()))
	if ch < fr:
		print(-1)
	elif fr == 2:
		print(-1)
	else:
		x = [[arr[i], i + 1] for i in range(fr)]
		x.sort()
		print(sum(arr) * 2 + (ch - fr) * (x[0][0] + x[1][0]))
		for i in range(fr):
			if i == fr - 1:
				print(1, fr)
			else:
				print(i + 1, i + 2)
		for i in range(fr, ch):
			print(x[0][1], x[1][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)


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


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
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')
for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ind = list()
	if n > m or n <= 2:
		print(-1)
		continue
	c = 0
	for i in range(n):
		ind.append((a[i], i + 1))
		c += a[i]
	ind.sort()
	c *= 2
	m = m - n
	c += m * (ind[1][0] + ind[0][0])
	print(c)
	print(ind[0][1], ind[n - 1][1])
	for i in range(n - 1):
		print(ind[i][1], ind[i + 1][1])
	for i in range(m):
		print(ind[0][1], ind[1][1])


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input()
t = I()
for i in range(0, t):
	(n, m) = li()
	b = li()
	a = []
	for i in range(0, n):
		a.append([b[i], i + 1])
	a.sort()
	s = 0
	ans = []
	if n == 2:
		print(-1)
		continue
	if m < n:
		print(-1)
		continue
	s = s + a[0][0] + a[n - 1][0]
	ans.append([a[0][1], a[n - 1][1]])
	for i in range(0, n - 1):
		s = s + a[i][0] + a[i + 1][0]
		ans.append([a[i][1], a[i + 1][1]])
	for i in range(n, m):
		s = s + a[0][0] + a[1][0]
		ans.append([a[0][1], a[1][1]])
	print(s)
	for i in ans:
		print(*i)


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):
	(person_num, chains_num) = map(int, input().split())
	fridges = list(map(int, input().split()))
	Last_fridges = fridges[:]
	fridges.sort()
	if person_num <= 2 or chains_num < person_num:
		print(-1)
	else:
		money_1 = 2 * sum(fridges)
		res = chains_num - person_num
		money_2 = res * (fridges[0] + fridges[1])
		res1 = fridges[0]
		res2 = fridges[1]
		location1 = Last_fridges.index(res1)
		location2 = Last_fridges.index(res2)
		print(money_1 + money_2)
		for x in range(person_num - 1):
			print(x + 1, x + 2)
		print(1, person_num)
		for j in range(res):
			print(location1, location2)


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


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 sys import stdin

def input():
	return stdin.readline().strip()
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	weight = list(map(int, input().split()))
	edges = [(i, (i + 1) % n) for i in range(n)]
	edges.sort(key=lambda x: weight[x[0]] + weight[x[1]])
	total = sum((weight[u] + weight[v] for (u, v) in edges))
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		(u, v) = edges[0]
		total += (weight[u] + weight[v]) * (m - n)
		print(total)
		for i in range(n):
			print(edges[i][0] + 1, edges[i][1] + 1)
		for j in range(m - n):
			print(edges[0][0] + 1, edges[0][1] + 1)


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


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')
testcases = int(input())
for j in range(testcases):
	(n, m) = map(int, input().split())
	weights = list(map(int, input().split()))
	if n <= 2:
		print(-1)
	elif m < n:
		print(-1)
	else:
		weights = [(weights[s], s) for s in range(len(weights))]
		weights.sort(key=lambda x: x[0])
		cost = 0
		indices = []
		for s in range(n):
			cost += weights[s][0] + weights[(s + 1) % n][0]
			indices.append((weights[s][1] + 1, weights[(s + 1) % n][1] + 1))
		for b in range(m - n):
			cost += weights[0][0] + weights[1 % n][0]
			indices.append((weights[0][1] + 1, weights[1 % n][1] + 1))
		print(cost)
		for b in range(len(indices)):
			print(*indices[b])


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)


tests = int(input())
while tests:
	tests -= 1
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
		continue
	l1 = sorted([(l[i], i + 1) for i in range(len(l))])
	edges = []
	cost = 0
	for i in range(n - 1):
		cost += l1[i][0] + l1[i + 1][0]
		edges.append([l1[i][1], l1[i + 1][1]])
	cost += l1[len(l1) - 1][0] + l1[0][0]
	edges.append([l1[len(l1) - 1][1], l1[0][1]])
	iters = m - n
	for i in range(iters):
		cost += l1[0][0] + l1[1][0]
		edges.append([l1[0][1], l1[1][1]])
	print(cost)
	for edge in edges:
		print(*edge)


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))


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
	sa = sorted(enumerate(a), key=lambda x: x[1])
	s = sum(a) * 2 + (sa[0][1] + sa[1][1]) * (m - n)
	print(s)
	print(sa[0][0] + 1, sa[-1][0] + 1)
	for i in range(len(a) - 1):
		print(sa[i][0] + 1, sa[i + 1][0] + 1)
	for i in range(m - n):
		print(sa[0][0] + 1, sa[1][0] + 1)


cases = int(input())
for _ in range(cases):
	(ppl, chains) = map(int, input().strip().split())
	w = list(map(int, input().strip().split()))
	weights = [(w[i], i + 1) for i in range(len(w))]
	weights.sort()
	if ppl == 2 or chains < ppl:
		print(-1)
		continue
	ans = 0
	for i in range(ppl):
		ans += w[i] * 2
	ans += (chains - ppl) * (weights[0][0] + weights[1][0])
	print(ans)
	for i in range(1, ppl):
		print(i, i + 1)
	print(1, ppl)
	for _ in range(chains - ppl):
		print(weights[0][1], weights[1][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])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	wei = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
	else:
		co = wei.copy()
		co.sort()
		print(sum(wei) * 2 + (m - n) * (co[0] + co[1]))
		for i in range(1, n):
			print(i, i + 1)
		print(1, n)
		for i in range(m - n):
			print(wei.index(co[0]) + 1, wei.index(co[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])


def main():
	T = int(input())
	for t in range(0, T):
		l = input().split(' ')
		n = int(l[0])
		m = int(l[1])
		f = input().split(' ')
		for i in range(0, len(f)):
			f[i] = int(f[i])
		if n == 2:
			print(str(-1))
			continue
		if m < n:
			print(str(-1))
			continue
		cost = 0
		pairs = []
		for i in range(0, n):
			cost += 2 * f[i]
			if i == n - 1:
				pairs.append((1, n))
			else:
				pairs.append((i + 1, i + 2))
		print(cost)
		for pair in pairs:
			print(str(pair[0]) + ' ' + str(pair[1]))
main()


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)


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


T = int(input())
for i in range(T):
	a = input().split()
	n = int(a[0])
	m = int(a[1])
	values = input().split()
	for j in range(n):
		values[j] = int(values[j])
	if m < n or n == 2:
		print(-1)
	else:
		s = sum(values)
		p = min(values)
		x = values.index(p) + 1
		values.remove(p)
		q = min(values)
		y = values.index(q) + 1
		if y >= x:
			y += 1
		print(2 * s + (m - n) * (p + q))
		print(str(1) + ' ' + str(n))
		for j in range(n - 1):
			print(str(j + 1) + ' ' + str(j + 2))
		for j in range(m - n):
			print(str(x) + ' ' + str(y))


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


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	sl = list(map(int, input().split()))
	l = sorted(sl)
	ans = 0
	if a > b or a == 2:
		print(-1)
		continue
	c = b - a
	ans += 2 * sum(l) + c * (l[0] + l[1])
	print(ans)
	for j in range(len(l) - 1):
		print(j + 1, j + 2)
	print(1, len(l))
	z = sl.index(l[0]) + 1
	for j in range(c):
		print(z, (sl[:z] + sl[z:]).index(l[1]) + 1 + z)


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')


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(n, m) = num()
		a = li()
		x = []
		for i in range(n):
			x.append((a[i], i + 1))
		if n == 2:
			print(-1)
			continue
		if n > m:
			print(-1)
			continue
		x.sort()
		oo = m - n
		zz = oo * (x[0][0] + x[1][0]) + sum(a) * 2
		print(zz)
		for i in range(n):
			op = i
			oz = (i + 1) % n
			print(x[op][1], x[oz][1])
		for i in range(oo):
			print(x[0][1], x[1][1])
solve()


def connect_fridges(n, m, prices):
	if m < n or n < 3:
		return -1
	cumsum = 0
	ans = []
	order = sorted(range(len(prices)), key=prices.__getitem__)
	for i in range(n - 1):
		cumsum += prices[order[i]] + prices[order[i + 1]]
		ans.append([str(order[i] + 1), str(order[i + 1] + 1)])
	cumsum += prices[order[-1]] + prices[order[0]]
	ans.append([str(order[-1] + 1), str(order[0] + 1)])
	return (cumsum, ans)
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	prices = list(map(int, input().split()))
	result = connect_fridges(n, m, prices)
	if type(result) == int:
		print(result)
	else:
		print(result[0])
		for i in range(m):
			print(' '.join(result[1][i]))


T = int(input())
for test_case in range(T):
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	weights = [int(w) for w in input().split(' ')]
	if m < n or n == 2:
		print(-1)
		continue
	cycle_weights = 2 * sum(weights)
	w1 = min(weights)
	v1 = weights.index(w1) + 1
	weights[v1 - 1] = 999999999
	w2 = min(weights)
	v2 = weights.index(w2) + 1
	weights[v2 - 1] = 999999999
	multiedge_weights = (m - n) * (w1 + w2)
	print(cycle_weights + multiedge_weights)
	print(1, m)
	for i in range(1, m):
		print(i, i + 1)
	for i in range(n - m):
		print(v1, v2)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

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

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, m) = sep()
	a = lis()
	if m < n or n < 3:
		print(-1)
		return
	for i in range(n):
		a[i] = [a[i], i + 1]
	a = sorted(a)
	sum = 0
	for i in range(0, n):
		sum += 2 * a[i][0]
	print(sum)
	for i in range(1, n):
		print(a[i - 1][1], a[i][1])
	print(a[0][1], a[n - 1][1])
testcase(int(inp()))


def main():

	def cmp_to_key(mycmp):

		class K(object):

			def __init__(self, obj, *args):
				self.obj = obj

			def __lt__(self, other):
				return mycmp(self.obj, other.obj) < 0

			def __gt__(self, other):
				return mycmp(self.obj, other.obj) > 0

			def __eq__(self, other):
				return mycmp(self.obj, other.obj) == 0

			def __le__(self, other):
				return mycmp(self.obj, other.obj) <= 0

			def __ge__(self, other):
				return mycmp(self.obj, other.obj) >= 0

			def __ne__(self, other):
				return mycmp(self.obj, other.obj) != 0
		return K
	(n, m) = map(int, input().split())
	q = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
	else:
		print(sum(q) * 2)
		for i in range(1, m):
			print(i, i + 1)
		print(1, n)
for qwerty in range(int(input())):
	main()


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

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

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

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

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(n, m) = mp()
	l = li()
	if n == 2:
		pr(-1)
		return
	if n != m:
		pr(-1)
		return
	pr(2 * sum(l))
	for i in range(1, m):
		print(i, i + 1)
	print(1, m)
for _ in range(inp()):
	solve()


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))


from collections import Counter
from collections import defaultdict
import math
import bisect
t = int(input())
for _ in range(0, t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = list()
	g = list()
	ans = 0
	if n == 2:
		print(-1)
		continue
	if m < n:
		print(-1)
		continue
	else:
		for i in range(0, n):
			l.append([a[i], i + 1])
	l.sort(key=lambda x: x[0])
	for i in range(0, n):
		ans = ans + l[i][0] + l[(i + 1) % n][0]
		g.append([l[i][1], l[(i + 1) % n][1]])
	if m - n != 0:
		for i in range(0, m - n):
			ans = ans + l[0][0] + l[1][0]
			g.append([l[0][1], l[1][1]])
	print(ans)
	for (i, j) in g:
		print(i, j)


from functools import reduce
from typing import List, Tuple
t = int(input())
for __ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sorted_idc = sorted(range(1, n + 1), key=lambda i: a[i - 1])
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		print(2 * sum(a) + (m - n) * (a[sorted_idc[0] - 1] + a[sorted_idc[1] - 1]))
		for i in range(n - 1):
			print(sorted_idc[i], sorted_idc[i + 1])
		print(sorted_idc[0], sorted_idc[n - 1])
		for i in range(m - n):
			print(sorted_idc[0], sorted_idc[1])


def sol():
	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
		dict = {}
		sum = 0
		for j in range(n):
			sum += a[j]
			dict[j + 1] = a[j]
		d = sorted(dict.items(), key=lambda x: x[1])
		ans = sum * 2 + (m - n) * (d[0][1] + d[1][1])
		print(ans)
		for j in range(1, n):
			print(j, ' ', j + 1)
		print(n, ' ', 1)
		for j in range(m - n):
			print(d[0][0], ' ', d[1][0])
sol()


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


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	if N == 0 or N == 2:
		print('-1')
	elif K < N:
		print('-1')
	elif N % 2 != 0 and K >= (N - 1) // 2 * 3:
		L.sort()
		cost = 0
		diff = K - (N - 1) // 2 * 3
		x = diff
		for i in range(1, N):
			cost = cost + L[0] + L[i]
			if i % 2 != 0:
				cost = cost + L[i] + L[i + 1]
		while x:
			cost = cost + L[0] + L[1]
			x -= 1
		print(cost)
		for i in range(1, N):
			print(1, i + 1)
			if i % 2 != 0:
				print(i + 1, i + 2)
		while diff:
			print(1, 2)
			diff -= 1
	else:
		cost = 0
		diff = K - N
		x = diff
		for i in range(N - 1):
			cost = cost + L[i] + L[i + 1]
		while x:
			cost = cost + L[0] + L[1]
			x -= 1
		cost = cost + L[0] + L[N - 1]
		print(cost)
		while diff:
			print(1, 2)
			diff -= 1
		for i in range(N - 1):
			print(i + 1, i + 2)
		print(1, N)


t = int(input())

def f(n, m, prices):
	total_price = 0
	if m < n or n < 3:
		print(-1)
		return
	else:
		total_price += 2 * sum(prices)
		m -= n
		min1 = min2 = 10000
		in1 = in2 = -1
		i = 0
		for price in prices:
			if price < min1:
				min2 = min1
				min1 = price
				in2 = in1
				in1 = i
			elif price < min2:
				min2 = price
				in2 = i
			i += 1
		total_price += m * (min1 + min2)
		print(total_price)
		for num in range(1, n):
			print(num, num + 1)
		print(1, n)
		if m > 0:
			for _ in range(m):
				print(in1, in2)
		return
for _ in range(t):
	(n, m) = map(int, input().split())
	prices = list(map(int, input().split()))
	f(n, m, prices)


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)


k = int(input())
for kk in range(k):
	(n, m) = [int(i) for i in input().split()]
	q = [int(i) for i in input().split()]
	if m < n or n == 2:
		print(-1)
	else:
		qq = q[:]
		qq.sort()
		print(sum(q) * 2 + (qq[0] + qq[1]) * (m - n))
		ii = q.index(qq[0])
		del q[ii]
		ij = q.index(qq[1])
		print(1, len(qq))
		for i in range(1, len(qq)):
			print(i, i + 1)
		for i in range(m - n):
			print(ii + 1, ij + 1)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def solution():
	for j in range(Int()):
		(n, m) = Mint()
		a = List()
		if m == n and n != 2:
			print(2 * sum(a))
			print(n, 1)
			for i in range(1, n):
				print(i, i + 1)
		else:
			print(-1)
solution()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if m < n or n == 2:
		print('-1')
		continue
	L = [[l[i], i + 1] for i in range(n)]
	L.sort()
	ans1 = 2 * sum(l)
	ans1 += (L[0][0] + L[1][0]) * (m - n)
	print(ans1)
	for i in range(n - 1):
		print(i + 1, i + 2)
	print(1, n)
	for i in range(m - n):
		print(L[0][1], L[1][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)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ai = list(map(int, input().split()))
	ui = [i for i in range(1, n + 1)]
	if n == 2:
		print(-1)
	elif n <= m:
		print(2 * sum(ai))
		count = 0
		for i in range(0, len(ui)):
			print(ui[i], ui[i - 1])
	else:
		print(-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)


t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split(' '))
	li = [int(x) for x in input().split()]
	edges = []
	edges_sum = 0
	if m <= n and m > 2:
		for i in range(0, m):
			edges.append((li[i] + li[(i + 1) % m], i, (i + 1) % m))
		if n > len(edges):
			min_edge = min(edges)
			for i in range(n - m):
				edges.append(min_edge)
		edges.sort()
		for i in range(0, n):
			edges_sum += edges[i][0]
		print(edges_sum)
		for i in range(n):
			print(edges[i][1] + 1, edges[i][2] + 1)
	else:
		print(-1)


from collections import defaultdict
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 2 or m < n:
		print(-1)
		continue
	ans = 0
	lst = []
	for i in range(n):
		a[i] = (a[i], i)
	mn = sorted(a)[:2]
	for i in range(1, n):
		ans += a[i][0] + a[i - 1][0]
		lst.append((i, i - 1))
	ans += a[0][0] + a[-1][0]
	lst.append((0, n - 1))
	d = m - len(lst)
	(uc, u) = mn[0]
	(vc, v) = mn[1]
	for i in range(d):
		lst.append((u, v))
	ans += (uc + vc) * d
	print(ans)
	for (a, b) in lst:
		print(a + 1, b + 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)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	count = 0
	l = [int(j) for j in input().split()]
	if m < n or n == 2:
		print('-1')
	else:
		for j in range(1, n):
			count += l[j - 1] + l[j]
		count += l[0] + l[n - 1]
		print(count)
		for j in range(1, n):
			print(j, j + 1, end=' ')
			print()
		print(n, 1, end=' ')
		print()


t = int(input())
while t > 0:
	(n, c) = map(int, input().split())
	cost = list(map(int, input().split()))
	index = [int(i) for i in range(0, n)]
	z = list(zip(cost, index))
	z.sort()
	(cost, index) = zip(*z)
	value = 0
	join = []
	if c < n or n == 2:
		print('-1')
	elif c == n:
		for i in range(0, n - 1):
			value += cost[i] + cost[i + 1]
			join.append((index[i], index[i + 1]))
		value += cost[0] + cost[len(cost) - 1]
		join.append((index[0], index[len(cost) - 1]))
		print(value)
		for (i, k) in join:
			print(i + 1, k + 1)
	elif m > n and m < 2 * (n - 1) - 1:
		k = 0
		l = len(cost)
		join = []
		for i in range(0, n - 2):
			value += cost[i] + cost[i + 1]
			join.append((index[i], index[i + 1]))
			k += 1
		value += 2 * cost[0] + cost[len(cost) - 1] + cost[len(cost) - 2] + cost[1]
		join.append((index[0], index[len(cost) - 1]))
		join.append((index[0], index[len(cost) - 2]))
		join.append((index[1], index[len(cost) - 1]))
		k += 3
		if k < c:
			for i in range(c - k):
				value += cost[0] + cost[1]
				join.append((index[0], index[1]))
		print(value)
		for (i, k) in join:
			print(i + 1, k + 1)
	else:
		join = []
		for i in range(1, n):
			value += cost[0] + cost[i]
			join.append((index[0], index[i + 1]))
			if i < n - 1:
				value += cost[1] + cost[i + 1]
				join.append((index[1], index[i + 1]))
			k += 1
		print(value)
		for (i, k) in join:
			print(i + 1, k + 1)
	t -= 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()


from operator import itemgetter
tcs = int(input())
for _ in range(tcs):
	(n, m) = map(int, input().split())
	frig = list(map(int, input().split()))
	frig2 = []
	for i in range(n):
		frig2.append([frig[i], i])
	if n == 2:
		print(-1)
		continue
	if n != m:
		print(-1)
		continue
	frig2.sort(key=itemgetter(0))
	res = 0
	for i in range(1, n):
		res += frig2[i][0] + frig2[i - 1][0]
	res += frig2[0][0] + frig2[n - 1][0]
	print(res)
	for i in range(n - 1):
		print(frig2[i][1] + 1, frig2[i + 1][1] + 1)
	print(frig2[n - 1][1] + 1, frig2[0][1] + 1)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

def solve():
	(n, m) = num_input()
	arr = list_input()
	if m < n or n <= 2:
		print(-1)
		return
	print(sum(arr) * 2)
	for i in range(1, n):
		print(i, i + 1)
	print(1, n)
t = int(input())
for _ in range(t):
	solve()


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())
	As = list(map(int, input().split()))
	if m >= n and n > 2:
		As.sort()
		cost = 0
		for i in range(m):
			cost += As[i]
		print(cost * 2)
		for i in range(1, n):
			print(i, i + 1)
		print(n, 1)
	else:
		print(-1)


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


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])


from sys import stdin, stdout
import math
from bisect import bisect_left, bisect_right
input = lambda : stdin.readline().strip()
print = lambda s: stdout.write(s)
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ls = list(map(int, input().split()))
	d = {}
	for i in range(1, n + 1):
		try:
			d[ls[i - 1]].append(i)
		except:
			d[ls[i - 1]] = [i]
	ls.sort()
	if m < n or n == 2:
		print('-1\n')
	else:
		print(str(2 * sum(ls) + (ls[0] + ls[1]) * (m - n)) + '\n')
		for i in range(1, n):
			print(str(i) + ' ' + str(i + 1) + '\n')
		print(str(1) + ' ' + str(n) + '\n')
		for i in range(m - n):
			if ls[0] != ls[1]:
				print(str(d[ls[0]][0]) + ' ' + str(d[ls[1]][0]) + '\n')
			else:
				print(str(d[ls[0]][0]) + ' ' + str(d[ls[1]][1]) + '\n')


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)


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


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)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list((int(i) for i in input().split()))
	d = ((i, c) for (c, i) in enumerate(arr))
	d = sorted(d)
	m1 = d[0]
	m2 = d[1]
	cost = 0
	pairs = []
	if n > m or n == 2:
		print(-1)
	elif n == m:
		print(2 * sum(arr))
		for i in range(n - 1):
			print(d[i][1] + 1, d[i + 1][1] + 1)
		print(d[n - 1][1] + 1, d[0][1] + 1)
	else:
		M = m
		for i in range(2, n):
			cost += m1[0] + m2[0] + 2 * d[i][0]
			M -= 2
		cost += (m1[0] + m2[0]) * M
		print(cost)
		for i in range(2, n):
			print(m1[1] + 1, d[i][1] + 1)
			print(m2[1] + 1, d[i][1] + 1)
		for i in range(M):
			print(m1[1] + 1, m2[1] + 1)


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)


for q in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	r = []
	if m < n or n <= 2:
		print(-1)
	else:
		c = 0
		r += ['1 2']
		c += a[0] + a[1]
		for i in range(1, n - 1):
			r.append(f'{i} {i + 2}')
			c += a[i - 1] + a[i + 1]
		r += [f'{n - 1} {n}']
		c += a[n - 1] + a[n - 2]
		min1 = a.index(min(a))
		x = a[min1]
		min2 = 100000
		for i in range(0, len(a)):
			if a[i] < min2 and i != min1:
				min2 = i
		y = a[min2]
		r += [f'{min1 + 1} {min2 + 1}'] * (m - n)
		c += (y + x) * (m - n)
		print(c)
		print('\n'.join(r))


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)


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

def arr_inp():
	return [int(x) for x in input().split()]
for i in range(int(input())):
	(n, m) = inp()
	a = arr_inp()
	if m < n or n == 2:
		print(-1)
	else:
		print(sum(a) * 2)
		for j in range(1, m):
			print(j, j + 1)
		print(1, m)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
	else:
		d = list(zip(a, range(n)))
		d.sort()
		s = 0
		res = []
		for i in range(n):
			if i < n - 1:
				s += d[i][0] + d[i + 1][0]
				res.append([d[i][1] + 1, d[i + 1][1] + 1])
			elif i == n - 1:
				s += d[i][0] + d[0][0]
				res.append([d[i][1] + 1, d[0][1] + 1])
		print(s)
		for q in res:
			print(*q)


import heapq
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n > m or n == 2:
		print(-1)
		continue
	s = 2 * sum(l)
	if n < m:
		for i in range(n):
			l[i] = (l[i], i + 1)
		heapq.heapify(l)
		a = heapq.heappop(l)
		b = heapq.heappop(l)
		s += (a[0] + b[0]) * (m - n)
	print(s)
	for i in range(n - 1):
		print(i + 1, i + 2)
	print(1, n)
	for i in range(m - n):
		print(a[1], b[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)


def comp(e):
	return e[0]
for i in range(int(input())):
	(n, m) = (int(s) for s in input().split())
	a = []
	k = 0
	for s in input().split():
		a.append((int(s), k))
		k += 1
	a.sort(key=comp)
	if n == 2 or m < n:
		print(-1)
		continue
	out_p = 0
	out = []
	for j in range(len(a) - 1):
		out_p += a[j][0] + a[j + 1][0]
		out.append((a[j][1] + 1, a[j + 1][1] + 1))
		m -= 1
	out_p += a[0][0] + a[-1][0]
	out.append((a[0][1] + 1, a[-1][1] + 1))
	m -= 1
	while m != 0:
		out_p += a[0][0] + a[1][0]
		out.append((a[0][1] + 1, a[1][1] + 1))
		m -= 1
	print(out_p)
	for el in out:
		print(str(el[0]) + ' ' + str(el[1]))


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print('-1')
	else:
		arr = []
		s = 2 * sum(a)
		for i in range(n):
			arr.append([a[i], i])
		arr = sorted(arr, key=lambda x: x[0])
		s += (m - n) * (arr[0][0] + arr[1][0])
		print(s)
		for i in range(n):
			print(arr[i][1] + 1, arr[(i + 1) % n][1] + 1)
		for i in range(n, m):
			print(arr[0][1] + 1, arr[1][1] + 1)
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = [int(j) for j in input().split()]
	if m < n or n == 2:
		print(-1)
		continue
	su = 2 * sum(arr)
	mi = min(arr[0], arr[1])
	prevmi = max(arr[0], arr[1])
	if arr[0] < arr[1]:
		ind1 = 0
		ind2 = 1
	else:
		ind2 = 0
		ind1 = 1
	for x in range(2, len(arr)):
		if arr[x] < mi:
			prevmi = mi
			mi = arr[x]
			ind2 = ind1
			ind1 = x
		elif arr[x] < prevmi:
			ind2 = x
			prevmi = arr[x]
	m -= n
	su += m * (mi + prevmi)
	print(su)
	aa = []
	print(1, n)
	for j in range(1, n):
		print(j, j + 1)
	for j in range(m):
		print(ind1 + 1, ind2 + 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)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	ans = 2 * sum(l)
	a1 = l[0]
	a2 = 0
	b1 = l[1]
	b2 = 1
	for i in range(1, a):
		if l[i] <= a1:
			b1 = a1
			b2 = a2
			a1 = l[i]
			a2 = i
	if b < a or a == 2:
		print('-1')
	else:
		ans += (b - a) * (l[a2] + l[b2])
		print(ans)
		for i in range(1, a):
			print(i, i + 1)
		print(1, a)
		for i in range(b - a):
			print(a2 + 1, b2 + 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)


k = int(input())
for i in range(k):
	(n, m) = map(int, input().split())
	ch = input()
	s = ch.split(' ')
	for i in range(n):
		s[i] = int(s[i])
	if n == 2 or m < n:
		print(-1)
	else:
		h = 2 * sum(s)
		s1 = sorted(s)
		h += (m - n) * (s1[0] + s1[1])
		print(h)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print('1', n)
		if n < m:
			a = s.index(s1[0]) + 1
			s[a - 1] = h
			b = s.index(s1[1]) + 1
			for i in range(m - n):
				print(a, b)


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)


from heapq import heapify, heappop, heappush
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)
		continue
	li = []
	for (i, j) in enumerate(a, 1):
		li.append((j, i))
	arr = li.copy()
	heapify(li)
	u = heappop(li)
	res = []
	first = u
	v = 0
	total = 0
	for i in range(n - 1):
		v = heappop(li)
		total += u[0] + v[0]
		res.append([u[1], v[1]])
		u = v
	res.append((v[1], first[1]))
	total += v[0] + first[0]
	m -= n
	if m > 0:
		heapify(arr)
		u = heappop(arr)
		v = heappop(arr)
		for i in range(m):
			res.append([u[1], v[1]])
			total += u[0] + v[0]
	print(total)
	for x in res:
		print(*x)


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)


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


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 inp():
	return map(int, input().split())

def arr_enu():
	return [[i + 1, int(x)] for (i, x) in enumerate(input().split())]

def get_col(arr, i):
	return [row[i] for row in arr]
for i in range(int(input())):
	(n, m) = inp()
	a = arr_enu()
	if m < n or n == 2:
		print(-1)
	else:
		a.sort(key=lambda x: x[1])
		print(sum(get_col(a, 1)) * 2)
		for j in range(n):
			if j == n - 1:
				print(a[j][0], a[0][0])
			else:
				print(a[j][0], a[j + 1][0])


def solve():
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n > m or m > n * (n - 1) // 2:
		print(-1)
	else:
		s = 0
		for i in range(n - 1):
			s += arr[i] + arr[i + 1]
		s += arr[0] + arr[-1]
		print(s)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(1, n)
[solve() for _ in range(int(input()))]


def result(array, m, n):
	d = {}
	for i in range(len(array)):
		if array[i] not in d:
			d[array[i]] = [i]
		else:
			d[array[i]].append(i)
	(least, secondLeast) = leastTwo(array)
	total = 2 * sum(array) + (m - n) * (least + secondLeast)
	indexOfLeast = array.index(least)
	indexOfSecondLeast = array.index(secondLeast)
	if indexOfSecondLeast == indexOfLeast:
		indexOfSecondLeast = d[least][1]
	ListOfIndexes = []
	for i in range(n - 1):
		ListOfIndexes.append([i, i + 1])
	ListOfIndexes.append([0, n - 1])
	for i in range(m - n):
		ListOfIndexes.append([indexOfLeast, indexOfSecondLeast])
	return (total, ListOfIndexes)

def leastTwo(array):
	for i in range(2):
		ind = i
		for j in range(i + 1, len(array)):
			if array[j] < array[ind]:
				ind = j
		(array[i], array[ind]) = (array[ind], array[i])
	return (array[0], array[1])
for i in range(int(input())):
	(n, m) = map(int, input().split())
	cost = list(map(int, input().split()))
	if n < 3:
		print(-1)
	elif m < n:
		print(-1)
	else:
		(total, ans) = result(cost, m, n)
		print(total)
		for (ind, index) in ans:
			print(ind + 1, index + 1)


import heapq
t = int(input())

def solution(n, m, ws):
	if m < n or n <= 2:
		print(-1)
		return
	ws1 = []
	for i in range(n):
		ws1.append((ws[i], i))
	ws1.sort()
	cost = 0
	solutions = []
	for i in range(n - 1):
		solutions.append((ws1[i][1], ws1[i + 1][1]))
		cost += ws1[i][0] + ws1[i + 1][0]
	solutions.append((ws1[0][1], ws1[n - 1][1]))
	cost += ws1[0][0] + ws1[n - 1][0]
	if m > n:
		for _ in range(m - n):
			solutions.append((ws1[0][1], ws1[1][1]))
		cost += (m - n) * (ws1[0][0] + ws1[1][0])
	print(cost)
	for s in solutions:
		print(s[0] + 1, s[1] + 1)
for _ in range(t):
	(n, m) = map(int, input().split())
	ws = list(map(int, input().split()))
	solution(n, m, ws)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
INF = 10 ** 20
I = lambda : list(map(int, input().split()))
from collections import defaultdict as dd
from math import gcd
(t,) = I()
while t:
	t -= 1
	(n, m) = I()
	a = I()
	for i in range(n):
		a[i] = [a[i], i]
	a.sort()
	if n <= 2 or m < n:
		print(-1)
		continue
	cost = 0
	ans = []
	for i in range(n):
		cost += 2 * a[i][0]
		ans.append([a[i][1], a[(i + 1) % n][1]])
	for j in range(len(ans), m):
		cost += a[0][0] + a[1][0]
		ans.append([a[0][1], a[1][1]])
	print(cost)
	for i in ans:
		print(i[0] + 1, i[1] + 1)


t = int(input().strip())
for i in range(t):
	(n, m) = map(int, input().strip().split())
	Z = [int(j) for j in input().strip().split()]
	min1 = min(Z)
	ind1 = Z.index(min1)
	if Z.count(min1) > 1:
		min2 = min1
		ind2 = Z[ind1 + 1:].index(min1) + ind1 + 1
	else:
		a = set(Z)
		a.remove(min1)
		min2 = min(a)
		ind2 = Z.index(min2)
	if n == 2 or m < n:
		print(-1)
	else:
		d = (min1 + min2) * (m - n)
		print(2 * sum(Z) + d)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(1, n)
		for j in range(m - n):
			print(ind1 + 1, ind2 + 1)


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


from collections import deque
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	done = [0] * n
	if m < n or n < 3:
		print(-1)
		continue
	ll = [(a[i], i) for i in range(n)]
	ll.sort()
	f = True
	wires = []
	cost = 0
	q = deque([i for i in range(n)])
	while q:
		rmv1 = q.popleft()
		if done[rmv1] == 1:
			rmv2 = q.popleft()
			wires.append((rmv1 + 1, rmv2 + 1))
			done[rmv2] += 1
			done[rmv1] += 1
			if done[rmv2] < 2:
				q.append(rmv2)
			cost += a[rmv1] + a[rmv2]
			m -= 1
		elif done[rmv1] == 0:
			rmv2 = q.popleft()
			rmv3 = q.popleft()
			done[rmv1] += 2
			done[rmv2] += 1
			done[rmv3] += 1
			wires.append((rmv1 + 1, rmv2 + 1))
			wires.append((rmv1 + 1, rmv3 + 1))
			cost += 2 * a[rmv1] + a[rmv2] + a[rmv3]
			if done[rmv2] < 2:
				q.append(rmv2)
			if done[rmv3] < 2:
				q.append(rmv3)
			m -= 2
	if m > 0:
		mn1 = float('inf')
		mn2 = float('inf')
		i1 = -1
		i2 = -1
		for i in range(n):
			if mn1 > a[i]:
				mn2 = mn1
				i2 = i1
				i1 = i
				mn = a[i]
			elif mn2 > a[i]:
				mn2 = a[i]
				i2 = i
		temp = [(i1 + 1, i2 + 1)] * m
		wires += temp
		cost += (mn1 + mn2) * m
		m = 0
	if not f:
		print(-1)
	else:
		print(cost)
		for i in wires:
			print(i[0], i[1])


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)


queries = int(input())
for x in range(queries):
	(n, m) = (int(x) for x in input().split())
	w = [int(x) for x in input().split()]
	w.sort()
	combos = []
	cost = 0
	if m < n or n == 2:
		print(-1)
		continue
	for x in range(-1, len(w) - 1):
		if x == -1:
			combos.append((len(w), x + 2))
		else:
			combos.append((x + 1, x + 2))
		cost += w[x] + w[x + 1]
		m -= 1
	while m > 0:
		combos.append((1, 2))
		cost += w[0] + w[1]
	print(cost)
	for x in combos:
		print(x[0], x[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)


from sys import stdin

def input():
	return stdin.readline().strip()
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	fn = lambda x: [int(x[1]), x[0]]
	weight = list(map(fn, enumerate(input().split(), 1)))
	weight.sort()
	if m < n or n == 2:
		print(-1)
	else:
		(i, j) = (0, n - 1)
		edges = []
		term = 1
		total = 0
		while i < j:
			add = weight[i][0] + weight[j][0]
			if term:
				edges.append((i + 1, j + 1, add))
				i += 1
			else:
				edges.append((j + 1, i + 1, add))
				j -= 1
			total += add
			term = not term
		edges.append((1, j + 1, weight[0][0] + weight[j][0]))
		total += weight[0][0] + weight[j][0]
		total += (weight[0][0] + weight[1][0]) * (m - n)
		print(total)
		for (u, v, w) in edges:
			print(u, v)
		for i in range(m - n):
			print(weight[0][1], weight[1][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)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	freeges = list(map(int, input().split()))
	tmp33 = max(freeges) + 1
	price = 0
	ans = []
	tmp2 = []
	if n > m:
		print(-1)
		continue
	if n < 3:
		print(-1)
		continue
	gg = []
	for i in range(n):
		tmp = freeges.index(min(freeges))
		price += freeges[tmp] * 2
		ans.append(tmp + 1)
		if i < 2:
			gg.append(tmp + 1)
		if i == 1:
			if m > n:
				add = m - n
				tmp2 += ([gg[0]] + [gg[1]]) * add
				price += add * (freeges[gg[0]] + freeges[gg[1]])
		freeges[tmp] = tmp33
		last = tmp
	tmp2 += [last + 1] + [gg[0]]
	print(price)
	for i in range(len(ans) - 1):
		print(ans[i], ans[i + 1])
	for i in range(0, len(tmp2), 2):
		print(tmp2[i], tmp2[i + 1])


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 operator import itemgetter
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = []
	c = 0
	d = []
	if n == 2:
		print(-1)
		continue
	if k < n:
		print(-1)
		continue
	else:
		for i in range(n):
			b.append((a[i], i))
		b.sort(key=itemgetter(0))
		i = 0
		while i < n - 1 and k > 0:
			d.append([b[i][1] + 1, b[i + 1][1] + 1])
			c += b[i][0] + b[i + 1][0]
			i += 1
			k -= 1
		if k > 0:
			d.append([b[-1][1] + 1, b[0][1] + 1])
			c += b[-1][0] + b[0][0]
			k -= 1
		while k > 0:
			d.append([b[0][1] + 1, b[1][1] + 1])
			c += b[0][0] + b[1][0]
			k -= 1
		print(c)
		for i in d:
			print(*i)


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))


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


def run_testcase():
	[n, m] = [int(x) for x in input().split()]
	ns = [int(x) for x in input().split()]
	if n == 2:
		print(-1)
		return
	if m < n:
		print(-1)
		return
	sum_ns = sum(ns)
	cost = 2 * sum_ns
	rest_m = m - n
	sorted_ns = list(sorted(ns))
	cheapest_edge = sorted_ns[0] + sorted_ns[1]
	cost += cheapest_edge * rest_m
	edges = [None] * m
	edges[0] = (1, n)
	for i in range(1, n):
		edges[i] = (i, i + 1)
	for i in range(rest_m):
		edges[n + i] = (sorted_ns[0], sorted_ns[1])
	print(cost)
	for edge in edges:
		print(edge[0], edge[1])
testcase_count = int(input())
for i in range(testcase_count):
	run_testcase()


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)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	t = 0
	c = 0
	ll1 = []
	ll2 = []
	if b < a or b > (a - 1) * a // 2:
		print('-1')
	else:
		c = 1
		ll1.append(a)
		ll2.append(1)
		t += l[a - 1]
		t += l[0]
		for i in range(a - 1):
			ll1.append(i + 1)
			t += l[i] + l[i + 1]
			ll2.append(i + 2)
			c += 1
			if c >= b:
				break
		for i in range(0, a, 2):
			if c >= b:
				break
			else:
				t += l[i] + l[i + 2]
				ll1.append(i + 1)
				ll2.append(i + 3)
				c += 1
		for i in range(2, a + 1, 2):
			if c >= b:
				break
			else:
				t += l[i] + l[i + 2]
				ll1.append(i)
				ll2.append(i + 2)
				c += 1
		print(t)
		for i in range(len(ll1)):
			print(ll1[i], ll2[i])


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)


x = int(input())
for i in range(x):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n > m:
		print(-1)
		continue
	if n == 2:
		print(-1)
		continue
	z = l.index(min(l))
	z2 = 1
	d = min(l)
	d2 = 999999
	for i2 in range(n):
		if l[i2] != d:
			d2 = min(d2, l[i2])
			if d2 == l[i2]:
				z2 = i2
	l.sort()
	print(sum(l) * 2 + (l[0] + l[1]) * (m - n))
	for i2 in range(n - 1):
		print(i2 + 1, i2 + 2)
	print(1, n)
	for i2 in range(m - n):
		print(z + 1, z2 + 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)


a1 = []
a2 = []
n1 = int(input())
n = 0
for i in range(n1):
	(a, b) = map(int, input().split())
	h = list(map(int, input().split()))
	s = 0
	if a > b or a == 2:
		a1.append(-1)
		a2.append(a)
	else:
		for i in range(a):
			s = s + h[i]
		s = s * 2
		a1.append(s)
		a2.append(a)
for i in range(n1):
	print(a1[i])
	if a1[i] != -1:
		for i1 in range(a2[i]):
			c = i1 + 2
			if i1 + 2 > a2[i]:
				c = (i1 + 2) % a2[i]
			print(i1 + 1, ' ', c)


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)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()

def method1(l, n, m):
	cost1 = 0
	ans = []
	for i in range(n - 1):
		ans.append((l[i][1] + 1, l[i + 1][1] + 1))
		cost1 += l[i][0] + l[i + 1][0]
		m -= 1
	m -= 1
	ans.append((l[n - 1][1] + 1, l[0][1] + 1))
	cost1 += l[n - 1][0] + l[0][0]
	while m != 0:
		ans.append((l[0][1] + 1, l[1][1] + 1))
		m -= 1
		cost1 += l[0][0] + l[1][0]
	return (cost1, ans)

def method2(l, n, m):
	cost1 = 0
	ans = []
	for i in range(1, n):
		ans.append((l[0][1] + 1, l[i][1] + 1))
		ans.append((l[0][1] + 1, l[i][1] + 1))
		cost1 += 2 * (l[0][0] + l[i][1])
		m -= 2
	while m != 0:
		ans.append((l[0][1] + 1, l[1][1] + 1))
		m -= 1
		cost1 += l[0][0] + l[1][0]
	return (cost1, ans)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	la = []
	for i in range(n):
		la.append([l[i], i])
	la.sort()
	if m < n or n == 2:
		print(-1)
	elif m < 2 * n:
		(cost, ans) = method1(la, n, m)
		print(cost)
		for i in ans:
			(a, b) = i
			print(a, b)
	else:
		(cost1, ans1) = method1(la, n, m)
		(cost2, ans2) = method2(la, n, m)
		if cost1 <= cost2:
			print(cost1)
			for i in ans1:
				(a, b) = i
				print(a, b)
		else:
			print(cost2)
			for i in ans2:
				(a, b) = i
				print(a, b)


def f():
	(n, m) = [int(s) for s in input().split()]
	A = [int(s) for s in input().split()]
	if n < 3:
		print(-1)
		return
	if m < n:
		print(-1)
		return
	index = list(range(n))
	index.sort(key=lambda x: A[x])
	min1 = index[0]
	min2 = index[1]
	minW = A[min1] + A[min2]
	sum = 0
	for a in A:
		sum += a
	c = sum * 2 + (m - n) * minW
	print(c)
	for i in range(1, n):
		print('{} {}'.format(i, i + 1))
	print('{} {}'.format(1, n))
	min1 += 1
	min2 += 1
	for i in range(m - n):
		print('{} {}'.format(min1, min2))
T = int(input())
for t in range(T):
	f()


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)


T = int(input())
while T:
	(n, m) = map(int, input().split())
	a = input().split()
	if n == 2:
		print(-1)
	else:
		b = []
		for i in range(n):
			b.append([int(a[i]), i])
		b.sort()
		if m >= n:
			cost = 0
			for i in range(n):
				cost += b[i][0] + b[(i + 1) % n][0]
			x = m - n
			while x:
				cost += b[0][0] + b[1][0]
				x -= 1
			print(cost)
			for i in range(n):
				print(b[i][1] + 1, b[(i + 1) % n][1] + 1)
			x = m - n
			while x:
				print(b[0][1] + 1, b[1][1] + 1)
				x -= 1
		else:
			print(-1)
	T -= 1


T = int(input())
for i in range(T):
	(n, m) = map(int, input().split())
	j = [int(elem) for elem in input().split()]
	c = 0
	if n > m or n <= 2:
		print(-1)
	else:
		for z in range(2, n + 1):
			c += j[z - 2] + j[z - 1]
		c += j[0] + j[n - 1]
		for x in range(m - n):
			c += j[0] + j[1]
		print(c)
		for z in range(2, n + 1):
			print(z - 1, z)
		print(1, n)
		for x in range(m - n):
			print(1, 2)


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())
for i in range(T):
	(n, m) = map(int, input().split())
	w = list(map(int, input().split()))
	if n != m or n == 2:
		print(-1)
	else:
		print(2 * sum(w))
		for i in range(1, n):
			print(i, i + 1)
		print(1, n)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	num = list(map(int, input().strip().split()))
	num = sorted(num)
	if m < n:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		print(2 * sum(num))
		for i in range(1, n):
			print(i, i + 1)
		print('1', n)
	t = t - 1


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)


def solve():
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	if m < n or n <= 2:
		print(-1)
		return
	cost = 0
	for i in range(n):
		if i == 0:
			cost += a[i] + a[n - 1]
		else:
			cost += a[i - 1] + a[i]
	sa = enumerate(a)
	sa = sorted(sa, key=lambda k: (k[1], k[0]))
	m -= n
	cost += m * (sa[1][1] + sa[0][1])
	print(cost)
	for i in range(n):
		if i == 0:
			print(n, 1)
		else:
			print(i, i + 1)
	for x in range(m):
		print(sa[1][0] + 1, sa[0][0] + 1)

def main():
	t = int(input())
	while t != 0:
		solve()
		t -= 1
main()


for _ in range(int(input())):
	(nPeople, nChains) = map(int, input().split())
	a = list(map(int, input().split()))
	if nPeople == 2 or nChains < nPeople:
		print(-1)
	else:
		ret = ['%s %s' % (1, nPeople)]
		for i in range(nPeople - 1):
			ret.append('%s %s' % (i + 1, i + 2))
		print(sum(a) * 2)
		print('\n'.join(ret))


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])


import heapq
from copy import deepcopy
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = deepcopy(a)
	d = []
	s = sum(a)
	heapq.heapify(a)
	if n == 2 or n > m:
		print(-1)
	else:
		for i in range(n - 1):
			d.append([i + 1, i + 2])
		d.append([1, n])
		x = heapq.heappop(a)
		y = heapq.heappop(a)
		xi = b.index(x)
		b[xi] = 10 ** 6
		yi = b.index(y)
		for i in range(m - n):
			d.append([xi + 1, yi + 1])
		print(s * 2 + (m - n) * (x + y))
		for i in range(len(d)):
			print(*d[i])


import sys
import heapq

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, m) = ilele()
	A = alele()
	if m < len(A):
		print(-1)
	elif n <= 2:
		print(-1)
	else:
		x = heapq.nsmallest(2, A)
		tot = sum(A) * 2
		tot += (m - len(A)) * sum(x)
		print(tot)
		for i in range(1, len(A)):
			print(i, i + 1)
		print(1, len(A))
		a = A.index(x[0]) + 1
		A[A.index(x[0])] = 1000000000
		b = A.index(x[1]) + 1
		for i in range(m - len(A)):
			print(a, b)


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))


t = int(input())
for i 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
	if m == n:
		print(2 * sum(a))
		for i in range(1, n):
			print(i, i + 1)
		print(1, n)


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())


n = int(input())
while n:
	[p, c] = input().split()
	p = int(p)
	c = int(c)
	w = [[int(i), j + 1, 2] for (i, j) in zip(input().split(), range(p))]
	n -= 1
	w.sort(reverse=True)
	if c < p or p < 3:
		print(-1)
		continue
	s = []
	connected = []
	t = 0
	while len(w):
		if len(w) > 1 or w[-1:][0][2] == 0:
			connected.append(w.pop())
		if len(w) == 0:
			break
		cur = w[-1:][0]
		for i in connected:
			if i[2]:
				i[2] -= 1
				cur[2] -= 1
				s.append([cur[1], i[1]])
				t += cur[0] + i[0]
				break
	print(t)
	for i in s:
		print(str(i[0]) + ' ' + str(i[1]))


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))


t = int(input())
j = 0
s = 0
m = []
while t:
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	if b < a or (a == 2 and b == 2):
		print(-1)
	else:
		d = b // a
		for i in range(0, a):
			s = s + l[i] * d * 2
		d = b % a
		m = l.copy()
		m.sort()
		temp = d
		while d:
			s = s + m[0] + m[1]
			d -= 1
		print(s)
		s = 0
		d = m[0]
		e = m[1]
		x = l.index(d)
		y = l.index(e)
		d = b // a
		while d > 0:
			for i in range(1, a):
				print(i, ' ', i + 1)
			print(a, ' ', 1)
			d = d - 1
		d = b % a
		while d:
			if m[0] == m[1]:
				print(x + 1, ' ', y + 2)
			else:
				print(x + 1, ' ', y + 1)
			d -= 1
	t -= 1


for y in range(int(input())):
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	t = 2 * sum(lst)
	if m < n or n < 3:
		print('-1')
		continue
	lst.sort()
	arr = [0] * n
	for i in range(n):
		arr[i] = [lst[i], i]
	arr.sort()
	t += (m - n) * (arr[0][0] + arr[1][0])
	print(t)
	for i in range(1, n):
		print(arr[i][1] + 1, arr[i - 1][1] + 1)
	for i in range(1):
		print(arr[0][1] + 1, arr[n - 1][1] + 1)
	for i in range(m - n):
		print(arr[0][1] + 1, arr[1][1] + 1)


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)


for i in range(int(input())):
	(n, m) = [int(j) for j in input().split()]
	a = [int(j) for j in input().split()]
	if n == 2 or m < n:
		print(-1)
	else:
		b = [j + 1 for j in range(n)]
		c = list(sorted(zip(a, b)))
		(a, b) = ([j[0] for j in c], [k[1] for k in c])
		print(int(sum(a) * 2 + (m - n) * (a[0] + a[1])))
		for j in range(n):
			print(b[j - 1], b[j])
		for k in range(m - n):
			print(b[0], b[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) = map(int, input().split())
	a = list(map(int, input().split()))
	r = min(a)
	c = 100000
	t = a.index(r)
	ans = 0
	u = sum(a)
	for j in range(n):
		if j != t:
			if c > a[j]:
				c = a[j]
				p = j
	if n > m:
		print(-1)
	elif n == 2:
		print(-1)
	elif n <= m and m < n - 1 + (n - 2):
		ans = 2 * u + (m - n) * (r + c)
		print(ans)
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(n, 1)
		for i in range(m - n):
			print(t + 1, p + 1)
	elif m >= n - 1 + (n - 2):
		ans = ans + u + (n - 2) * r
		ans = ans + u - r + (n - 2) * c - c
		if m - (n - 1) - (n - 2) > 0:
			ans = ans + (m - (n - 1) - (n - 2)) * (r + c)
		print(ans)
		for i in range(n):
			if i != t:
				print(t + 1, i + 1)
		for i in range(n):
			if i != t and i != p:
				print(p + 1, i + 1)
		for i in range(m - (n - 1) - (n - 2)):
			print(t + 1, p + 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)


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	ans = []
	if n > m or n == 2:
		print(-1)
		continue
	mat = []
	for i in range(n):
		mat.append([])
		mat[-1].append(ar[i])
		mat[-1].append(i)
	summ = 0
	mat.sort()
	for i in range(n - 1):
		ans.append([])
		ans[-1].append(i + 1)
		ans[-1].append(i + 2)
		summ = summ + (ar[i] + ar[i + 1])
		m -= 1
	m -= 1
	summ += ar[n - 1]
	summ += ar[0]
	ans.append([])
	ans[-1].append(1)
	ans[-1].append(n)
	summ += m * (mat[0][0] + mat[1][0])
	print(summ)
	for i in range(m):
		print(mat[0][1], mat[1][1])
	for i in range(len(ans)):
		print(*ans[i])


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')


T = int(input())
for t in range(T):
	(N, M) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	if M < N:
		print('-1')
	elif M > N * int((N - 1) / 2):
		print(-1)
	elif M == N:
		Sum = sum(arr) * 2
		print(Sum)
		print(str(M), 1)
		for i in range(M - 1):
			print(i + 1, i + 2)


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)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 2 or n > m:
		print(-1)
	else:
		q = []
		for i in range(n):
			q += [[l[i], i + 1]]
		l.sort()
		q.sort()
		c = 0
		ch = ''
		for i in range(n - 1):
			c += l[i] + l[i + 1]
			ch += str(q[i][1]) + ' ' + str(q[i + 1][1]) + '\n'
		c += l[0] + l[n - 1]
		ch += str(q[0][1]) + ' ' + str(q[n - 1][1]) + '\n'
		if m > n:
			for i in range(m - n - 1):
				c += l[0] + l[1]
				ch += str(q[0][1]) + ' ' + str(q[1][1]) + '\n'
			c += l[0] + l[1]
			ch += str(q[0][1]) + ' ' + str(q[1][1])
		print(c)
		print(ch)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	(n, m) = mi()
	a = li()
	s = []
	if n > 2 and m >= n:
		s.append([1, n])
		for i in range(1, n):
			s.append([i, i + 1])
		x = sum(a) * 2
		z = min(a)
		u = a.index(z)
		a.remove(z)
		y = min(a)
		v = a.index(y)
		if v >= u:
			v += 1
		print(x + (z + y) * (m - n))
		for i in s:
			print(*i)
		for _ in range(m - n):
			print(u + 1, v + 1)
	else:
		print(-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)


a = []
for i in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	k = [int(i) for i in input().split()]
	if n > m or n == 2:
		a.append(0)
	else:
		a.append(k)
for k in a:
	if k == 0:
		print(-1)
	else:
		print(2 * sum(k))
		print(len(k), 1)
		for v in range(1, len(k)):
			print(v, v + 1)


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


t = int(input())
otv = []
for i in range(t):
	sp = input().split()
	n = int(sp[0])
	m = int(sp[1])
	s = input().split()
	sp = []
	summ = 0
	for j in s:
		sp.append(int(j))
	s = []
	if n == 1 or n == 2:
		otv.append(-1)
	elif m != n:
		otv.append(-1)
	else:
		x = len(otv)
		for j in range(n):
			summ += sp[j] + sp[j - 1]
			if j != n - 1:
				otv.append('{} {}'.format(j + 1, j + 2))
			else:
				otv.append('{} {}'.format(1, j + 1))
		otv.insert(x, summ)
for i in otv:
	print(i)


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())
	a = list(map(int, input().split()))
	if m < n or n == 2:
		print(-1)
		continue
	(x, y, *_) = sorted(a)
	print(2 * sum(a) + (m - n) * (x + y))
	print(n, 1)
	for i in range(1, n):
		print(i, i + 1)
	u = a.index(x) + 1
	v = len(a) - a[::-1].index(y)
	for _ in range(m - n):
		print(u, v)


t = int(input())
for t1 in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n < 3:
		print(-1)
		continue
	d = []
	for i in range(n):
		d.append((a[i], i + 1))
	b = sorted(d)
	con = []
	mincon = b[0][0] + b[1][0]
	c = 0
	for i in range(n):
		if i == 0:
			con.append((b[i][1], b[i + 1][1]))
			c += b[i][0] + b[i + 1][0]
		elif i < n - 1:
			con.append((b[i][1], b[i + 1][1]))
			c += b[i][0] + b[i + 1][0]
		else:
			con.append((b[i][1], b[0][1]))
			c += b[i][0] + b[0][0]
	if len(con) > m:
		print(-1)
	else:
		w = m - len(con)
		print(mincon * w + c)
		con += [(b[0][1], b[1][1])] * w
		for i in range(len(con)):
			print(con[i][0], con[i][1])


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)


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = [int(a) for a in input().split()]
	if n == 2 or n > m:
		print('-1')
		continue
	ans = 0
	for key in a:
		ans += key * 2
	b = sorted(a)
	ans += (m - n) * (b[0] + b[1])
	print(ans)
	for i in range(1, n):
		print(str(i) + ' ' + str(i + 1))
	print(str(1) + ' ' + str(n))
	for i in range(m - n):
		print(str(a.index(b[0] + 1)) + ' ' + str(a.index(b[1] + 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])


def solve():
	inp = input().split()
	n = int(inp[0])
	m = int(inp[1])
	A = input().split()
	if m < n or n < 3:
		print(-1)
		return
	suma = 0
	for a in A:
		suma += 2 * int(a)
	print(suma)
	for i in range(1, n):
		print(i, i + 1)
	print(1, n)
t = int(input())
while t > 0:
	solve()
	t -= 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)


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


test_cases = int(input())
for t in range(test_cases):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m < n - 1 or m <= 2:
		print(-1)
	elif m == n:
		print(2 * sum(a))
		for index in range(len(a) - 1):
			print(index + 1, index + 2)
		print(len(a), 1)


t = int(input())
while t:
	t += -1
	(n, m) = [int(x) for x in input().split()]
	l = list(map(int, input().split()))
	if n > m:
		print(-1)
	elif n == 2:
		print(-1)
	else:
		ans = 0
		mn1 = l[0]
		ind1 = 0
		for i in range(n):
			if l[i] < mn1:
				mn1 = l[i]
				ind1 = i
			ans += 2 * l[i]
		mn2 = 999999
		ind2 = 0
		for i in range(n):
			if i != ind1:
				if l[i] < mn2:
					mn2 = l[i]
					ind2 = i
		dif = m - n
		ans += dif * (mn1 + mn2)
		print(ans)
		for i in range(1, n):
			print(i, i + 1)
		print(1, n)
		for i in range(dif):
			print(ind1 + 1, ind2 + 1)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if n == 2:
		print(-1)
	elif n > m:
		print(-1)
	else:
		ans = []
		cnt = 0
		for i in range(1, n):
			ans.append([i, i + 1])
		ans.append([1, n])
		cnt += 2 * sum(arr)
		scores = []
		for i in range(n):
			scores.append([arr[i], i + 1])
		scores.sort()
		n1 = scores[0]
		n2 = scores[1]
		t = m - n
		cnt += t * (n1[0] + n2[0])
		print(cnt)
		for i in ans:
			print(*i)
		for i in range(t):
			print(n1[1], n2[1])


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


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)


import math
T = int(input())
val = [list(map(int, input().split())) for i in range(2 * T)]
for i in range(T):
	n = val[2 * i][0]
	m = val[2 * i][1]
	a = val[2 * i + 1][:]
	if m < n or n == 2:
		print(-1)
	else:
		x = sum(a)
		print(2 * x)
		for j in range(n - 1):
			print(j + 1, ' ', j + 2)
		print(n, ' ', 1)


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:
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	arr = [n]
	b = [n]
	arr = list(map(int, input().split()))
	ans = 0
	x = 0
	if m < n:
		ans = -1
		print(ans)
	elif n == 2:
		ans = -1
		print(ans)
	else:
		b = sorted(arr)
		for i in range(0, n - 1):
			ans = ans + b[i] + b[i + 1]
		ans = ans + b[0] + b[n - 1]
		m = m - n
		x = m
		while m > 0:
			ans = ans + b[0] + b[1]
			m = m - 1
		print(ans)
		for i in range(0, n - 1):
			print(i + 1, i + 2)
		print(1, n)
		while x > 0:
			print(1, 2)
			x = x - 1
	t = t - 1


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


q = int(input())
for _ in range(q):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	if m < n or n == 2:
		print(-1)
		continue
	a = sorted([[a[i], i + 1] for i in range(len(a))])
	ans = []
	k = 0
	for i in range(-1, len(a) - 1):
		ans.append([a[i][1], a[i + 1][1]])
		k += a[i][0] + a[i + 1][0]
	print(k)
	for i in range(len(ans)):
		print(ans[i][0], ans[i][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 i in ' ' * int(input()):
	(n, m) = map(int, input().split())
	L = list(map(int, input().split()))
	if n < 3:
		print(-1)
		continue
	if n > m:
		print(-1)
		continue
	else:
		min1 = min(L)
		index1 = L.index(min1)
		LL = L[:]
		LL.pop(index1)
		min2 = min(LL)
		index2 = LL.index(min2)
		if index2 >= index1:
			index2 += 1
		print(sum(L) * 2 + (m - n) * (min1 + min2))
		for i in range(n):
			if i < n - 1:
				print(i + 1, i + 2)
			else:
				print(1, i + 1)
		for i in range(m - n):
			print(index1 + 1, index2 + 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])


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


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if m < n or n == 2:
		print(-1)
	else:
		x1 = min(a)
		x = a.index(x1)
		a[x] += 10001
		y1 = min(a)
		y = a.index(y1)
		a[x] -= 10001
		print(2 * sum(a) + (m - n) * (x1 + y1))
		for i in range(1, n):
			print(i, i + 1)
		print(1, n)
		for i in range(m - n):
			print(x + 1, y + 1)


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = []
	i = 0
	for e in input().split():
		a.append((int(e), i + 1))
		i += 1
	if n == 2 or n > m:
		print('-1')
		continue
	ans = 0
	for key in a:
		ans += key[0] * 2
	a.sort(key=lambda x: x[0])
	ans += (m - n) * (a[0][0] + a[1][0])
	print(ans)
	for i in range(1, n):
		print(str(i) + ' ' + str(i + 1))
	print(str(1) + ' ' + str(n))
	for i in range(m - n):
		print(str(a[0][1]) + ' ' + str(a[1][1]))


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


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = sorted(zip(a, list(range(n))))
	if n == 2 or m < n:
		print(-1)
	else:
		c = 0
		l = []
		for i in range(m):
			l.append((x[i % n][1] + 1, x[(i + 1) % n][1] + 1))
			c += x[i % n][0] + x[(i + 1) % n][0]
		print(c)
		for i in l:
			print(*i)


t = int(input())
while t:
	cou = 0
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l = [(l[i], i) for i in range(n)]
	p = []
	l.sort()
	if n > m or n == 2:
		print(-1)
	else:
		for i in range(1, n):
			cou += l[i][0] + l[i - 1][0]
			p.append((l[i][1] + 1, l[i - 1][1] + 1))
			m -= 1
		cou += l[0][0] + l[-1][0]
		p.append((l[0][1] + 1, l[-1][1] + 1))
		m -= 1
		while m:
			cou += l[0][0] + l[1][0]
			p.append((l[0][1] + 1, l[1][1] + 1))
			m -= 1
		print(cou)
		for i in p:
			print(*i)
	t -= 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())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if arr[0] < arr[1]:
		min1 = arr[0]
		index1 = 1
		min2 = arr[1]
		index2 = 2
	else:
		min1 = arr[1]
		min2 = arr[0]
		index1 = 2
		index2 = 1
	for j in range(2, n):
		if arr[j] < min2:
			if arr[j] < min1:
				min1 = arr[j]
				index1 = j + 1
			else:
				min2 = arr[j]
				index2 = j + 1
	if m < n or n == 2:
		print(-1)
	else:
		ans = sum(arr) * 2 + (m - n) * (min1 + min2)
		print(ans)
		for j in range(1, n):
			print(j, j + 1)
		print(1, n)
		for j in range(m - n):
			print(index1, index2)


a = int(input())
for i in range(a):
	(n, m) = map(int, input().split(' '))
	l = [int(x) for x in input().split(' ')]
	if m < n:
		print('-1')
	elif n == 2:
		print('-1')
	else:
		sum = 0
		for i in range(n):
			sum = sum + l[i]
		sum = 2 * sum
		t = l
		t.sort()
		w = t[0]
		x = t[1]
		sum = sum + (m - n) * (w + x)
		print(sum)
		for i in range(n - 1):
			print(i + 1, end=' ')
			print(i + 2)
		print('1', end=' ')
		print(n)
		if w != x:
			q = l.index(w)
			r = l.index(x)
			for i in range(m - n):
				print(q + 1, end=' ')
				print(r + 1)
		else:
			k = []
			for i in range(n):
				if l[i] == w:
					k.append(i)
			for i in range(m - n):
				print(k[0] + 1, end=' ')
				print(k[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)


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)
	else:
		print(2 * sum(a) + (m - n) * min(a))
		for i in range(n - 1):
			print(i + 1, i + 2)
		print(1, n)
		t = a.index(min(a))
		for i in range(m - n):
			print(t + 2, t + 1)


T = int(input())
for j in range(T):
	(n, m) = map(int, input().strip().split())
	A = [int(iiii) for iiii in input().strip().split()]
	if m < n or n < 3:
		print(-1)
		continue
	print(sum(A) * 2)
	for i in range(1, n):
		print(i, i + 1)
	print(1, n)
	M = [0, 1]
	for i in range(2, len(A)):
		if max([A[M[0]], A[M[1]]]) > A[i]:
			if A[M[0]] > A[M[1]]:
				M[0] = i
			else:
				M[1] = i
	for i in range(n, m):
		print(M[0] + 1, M[1] + 1)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	wt = list(map(int, input().split()))
	if n != m or n == 2:
		print(-1)
	else:
		w = []
		for i in range(n):
			w.append([wt[i], i + 1])
		w.sort()
		i = 0
		j = n - 1
		ans = []
		c = 0
		while i <= j:
			if i != j:
				ans.append(w[j][1])
				ans.append(w[i][1])
			else:
				ans.append(w[i][1])
			i = i + 1
			j = j - 1
		ans.append(ans[0])
		for i in range(1, len(ans)):
			c = c + w[ans[i - 1] - 1][0] + w[ans[i] - 1][0]
		print(c)
		for i in range(1, len(ans)):
			print(ans[i - 1], ans[i])