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