#include <bits/stdc++.h>
using namespace std;
// Speed
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// Typedefs
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'
void solve() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> a(n);
int sum_others = 0;
for(int i = 0; i < n; i++) {
cin >> a[i].ff;
a[i].ss = i + 1; // Store original 1-based index
}
// Sort elves by value (smallest to largest)
sort(all(a));
// --- CASE 1: m = 0 (Kill Everyone) ---
if (m == 0) {
// Calculate sum of all attackers (excluding the King at n-1)
int current_king_hp = a[n-1].ff;
for(int i = 0; i < n - 1; i++) sum_others += a[i].ff;
// Impossible if we lack the damage to kill the King
if (sum_others < current_king_hp) {
cout << -1 << endl;
return;
}
vector<pair<int, int>> moves;
// Logic: Attack King if he can survive it. If not, waste the attacker on the next elf.
// We MUST ensure the King only dies on the very last attack.
for(int i = 0; i < n - 1; i++) {
// If this is the LAST attacker, we must attack the King to finish the game.
if (i == n - 2) {
moves.pb({a[i].ss, a[n-1].ss});
}
// If King can survive this attack, hit him.
else if (current_king_hp > a[i].ff) {
moves.pb({a[i].ss, a[n-1].ss});
current_king_hp -= a[i].ff;
}
// If King would die too early, waste this attacker on the next attacker.
else {
moves.pb({a[i].ss, a[i+1].ss});
// a[i] dies. a[i+1] takes damage but survives (since a[i+1] > a[i]).
// We don't need to track a[i+1]'s health precisely, just know it lives.
}
}
cout << sz(moves) << endl;
for(auto p : moves) cout << p.ff << " " << p.ss << endl;
return;
}
// --- CASE 2: m > 0 (Keep m Survivors) ---
// We need m victims for m survivors to safely "attack" and lock themselves.
// Constraint: n must be at least 2*m
if (n < 2 * m) {
cout << -1 << endl;
return;
}
// Groups logic (based on sorted array):
// Trash: Indices 0 to (n - 2m - 1)
// Targets: Indices (n - 2m) to (n - m - 1)
// Survivors: Indices (n - m) to (n - 1)
vector<pair<int, int>> moves;
// 1. Process Trash (Chain them to get rid of them)
int trash_count = n - 2 * m;
int first_target_idx = n - 2 * m;
if (trash_count > 0) {
for (int i = 0; i < trash_count; i++) {
if (i == trash_count - 1) {
// Last trash attacks the first target
moves.pb({a[i].ss, a[first_target_idx].ss});
} else {
// Trash attacks next trash
moves.pb({a[i].ss, a[i+1].ss});
}
}
}
// 2. Survivors attack Targets
// We pair Survivor[k] with Target[k]
for (int i = 0; i < m; i++) {
int target_idx = n - 2 * m + i;
int survivor_idx = n - m + i;
// Survivor attacks Target
// Survivor is stronger, so Survivor lives. Target dies.
moves.pb({a[survivor_idx].ss, a[target_idx].ss});
}
// Output
cout << sz(moves) << endl;
for(auto p : moves) {
cout << p.ff << " " << p.ss << endl;
}
}
int32_t main() {
fast_io;
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}