#include <bits/stdc++.h>
using namespace std;
void solve(int n, int p) {
  int cnt = 0;
  int i = 0;
  while (1) {
    if (cnt >= 2 * n + p) break;
    for (int j = i + 1; (j < n) && cnt < 2 * n + p; j++) {
      cout << i + 1 << " " << j + 1 << endl;
      cnt++;
    }
    i++;
  }
}
int main() {
  int T, n, p;
  cin >> T;
  for (int t = 1; t <= T; ++t) {
    cin >> n >> p;
    solve(n, p);
  }
  return 0;
}
