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