#include <bits/stdc++.h>
using namespace std;
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    int n, p;
    cin >> n >> p;
    vector<vector<int> > v(n, vector<int>(n, 0));
    int count = 0;
    try {
      for (int i = 1; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          if (!v[j][(j + i) % n]) {
            v[j][(j + i) % n] = true;
            v[(j + i) % n][j] = true;
            if (++count == 2 * n + p) {
              throw 0;
            }
          }
        }
      }
    } catch (...) {
      for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
          if (v[i][j]) {
            cout << i + 1 << " " << j + 1 << endl;
          }
        }
      }
    }
  }
  return 0;
}
