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