#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > cost_node, ans;
int grid[1010][1010];
int main() {
  int t, i, node, edge, cnt, x, j, tot;
  cin >> t;
  while (t--) {
    cin >> node >> edge;
    for (i = 0; i < node; i++) cin >> x, cost_node.push_back({x, i + 1});
    if (edge < node or edge > ((node - 1) * node) / 2)
      cout << -1 << endl;
    else {
      sort(cost_node.begin(), cost_node.end());
      memset(grid, -1, sizeof(grid));
      for (i = 0, tot = 0; i < node; i++) {
        if (i == node - 1) {
          grid[cost_node[i].second][cost_node[0].second] = 0,
          grid[cost_node[0].second][cost_node[i].second] = 0;
          ans.push_back({cost_node[i].second, cost_node[0].second});
          tot += cost_node[i].first + cost_node[0].first;
        } else {
          grid[cost_node[i].second][cost_node[i + 1].second] = 0,
                                                  grid[cost_node[i + 1].second]
                                                      [cost_node[i].second] = 0;
          ans.push_back({cost_node[i].second, cost_node[i + 1].second});
          tot += cost_node[i].first + cost_node[i + 1].first;
        }
      }
      cnt = node;
      for (i = 1; i <= node and cnt < edge; i++)
        for (j = 1; j <= node and cnt < edge; j++) {
          if (grid[i][j] == -1 and i != j) {
            grid[i][j] = 0;
            ans.push_back({cost_node[i].second, cost_node[j].second});
            grid[j][i] = 0;
            tot += cost_node[i].first + cost_node[j].first;
            cnt++;
          }
        }
      cout << tot << endl;
      for (i = 0; i < ans.size(); i++)
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    ans.clear(), cost_node.clear();
  }
  return 0;
}
