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