#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: We want 0 survivors ---
if (m == 0) {
int king_idx = n - 1;
int king_hp = a[king_idx].ff;
// Calculate damage potential from all others
int total_dmg = 0;
for(int i = 0; i < n - 1; i++) total_dmg += a[i].ff;
if (total_dmg < king_hp) {
cout << -1 << endl;
return;
}
vector<pair<int, int>> moves;
// Smallest elves attack the King until King dies
for(int i = 0; i < n - 1; i++) {
moves.pb({a[i].ss, a[king_idx].ss});
king_hp -= a[i].ff; // King takes damage
if (king_hp <= 0) break; // Stop if King is dead
}
cout << sz(moves) << endl;
for(auto p : moves) cout << p.ff << " " << p.ss << endl;
return;
}
// --- CASE 2: We want m survivors ---
// We need m victims for m survivors to safely "attack" and lock themselves.
// Total needed: m (Survivors) + m (Victims) = 2m.
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)
// Trash 0 -> Trash 1 -> ... -> Trash Last -> Target 0
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[i] with Target[i]
for (int i = 0; i < m; i++) {
int target_idx = n - 2 * m + i;
int survivor_idx = n - m + i;
// Survivor attacks Target
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;
}