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