#include <bits/stdc++.h>
int main() {
  int n, p, t;
  while (~scanf("%d", &t)) {
    while (t--) {
      scanf("%d%d", &n, &p);
      int e = 0;
      for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
          if (e < 2 * n + p) printf("%d %d\n", i, j);
          ++e;
        }
      }
    }
  }
  return 0;
}
