#include <bits/stdc++.h>
using namespace std;
int G[30][30];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, p, tst;
  cin >> tst;
  while (tst--) {
    cin >> n >> p;
    memset(G, 0, sizeof(G));
    for (int i = 0; i < int(5); i++)
      for (int j = 0; j < int(i); j++) G[j][i] = G[i][j] = 1;
    for (int u = int(5); u < int(n); u++)
      G[0][u] = G[u][0] = G[1][u] = G[u][1] = 1;
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(i); j++)
        if (G[i][j] == 0 && p > 0) {
          G[i][j] = G[j][i] = 1;
          p--;
        }
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(i); j++)
        if (G[i][j] == 1) {
          cout << i + 1 << " " << j + 1 << '\n';
        }
  }
  return 0;
}
