#include <bits/stdc++.h>
using namespace std;
void solve(int n, int p) {
  int con[25] = {};
  bool used[25][25] = {};
  for (int i = 1; i <= n; ++i) used[i][i] = true;
  for (int e = 0; e < n * 2 + p; ++e) {
    int mn = 0x7f7f7f7f;
    int bi = -1, bu = -1;
    for (int i = 1; i <= n; ++i) {
      for (int u = 1; u <= n; ++u) {
        if (!used[i][u]) {
          if (con[i] + con[u] < mn) {
            mn = con[i] + con[u];
            bi = i;
            bu = u;
          }
        }
      }
    }
    con[bi]++;
    con[bu]++;
    used[bi][bu] = used[bu][bi] = true;
    cout << bi << ' ' << bu << endl;
  }
}
int main() {
  int t;
  cin >> t;
  for (int e = 0; e < t; ++e) {
    int n, p;
    cin >> n >> p;
    solve(n, p);
  }
  return 0;
}
