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