#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1, tc;
  int i, j, k, l, m, n;
  int x, y, z, u, w, xx, yy, zz, d, h;
  int aa, bb, cc, p, dd;
  cin >> tc;
  while (tc--) {
    cin >> n >> p;
    int fl = 1;
    l = 2 * n + p;
    for (i = 1; i <= n && fl; i++) {
      for (j = i + 1; j <= n && fl; j++) {
        if (l) {
          printf("%d %d\n", i, j);
          l--;
        } else
          fl = 0;
      }
    }
  }
  return 0;
}
