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