#include <bits/stdc++.h>
using namespace std;
bool g[25][25];
int n, p;
int main() {
  int t;
  cin >> t;
  for (; t; --t) {
    cin >> n >> p;
    memset(g, 0, sizeof(g));
    int q = 2 * n + p;
    int sz = 0;
    for (int k = 1; k < n && sz < q; ++k) {
      for (int i = 0; i < n && sz < q; ++i)
        g[(i + k) % n][i] = g[i][(i + k) % n] = 1, sz++;
    }
    for (int i = 0; i < n; ++i)
      for (int j = i + 1; j < n; ++j)
        if (g[i][j]) printf("%d %d\n", i + 1, j + 1);
  }
  return 0;
}
