#include <bits/stdc++.h>
using namespace std;
int t, n, m, cnt;
pair<int, int> A[1003];
int C[1003][1003];
long Ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> A[i].first;
      A[i].second = i;
    }
    sort(A + 1, A + 1 + n);
    if (m < n || n <= 2)
      cout << -1 << '\n';
    else {
      Ans = 0;
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) C[i][j] = 0;
      if ((n - 1) + (n - 2) > m) {
        Ans = A[1].first + A[n].first;
        for (int i = 1; i < n; i++) {
          Ans += A[i].first + A[i + 1].first;
          C[i][i + 1]++;
        }
        C[n][1]++;
        m -= n;
      }
      while (m != 0) {
        cnt++;
        for (int i = 1; i <= n; i++) {
          for (int j = i + 1; j <= n; j++) {
            if (C[A[i].second][A[j].second] < cnt) {
              Ans += A[i].first + A[j].first;
              C[A[i].second][A[j].second]++;
              m--;
              if (m == 0) break;
            }
          }
          if (m == 0) break;
        }
      }
      cout << Ans << '\n';
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          if (C[i][j] != 0)
            for (int k = 1; k <= C[i][j]; k++) cout << i << ' ' << j << '\n';
        }
      }
    }
  }
  return 0;
}
