#include <bits/stdc++.h>
using namespace std;
int main() {
  int testCount;
  cin >> testCount;
  for (; testCount > 0; --testCount) {
    int n, p;
    cin >> n >> p;
    int e = 2 * n + p;
    for (int x = 1; x <= n && e > 0; ++x)
      for (int y = x + 1; y <= n && e > 0; ++y, --e)
        cout << x << " " << y << "\n";
  }
  return 0;
}
