#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, n, p, b, w, c1;
  cin >> t;
  while (t--) {
    c1 = 0;
    cin >> n >> p;
    p += 2 * n;
    for (int i = 1; i <= n && p; ++i) {
      for (int j = i + 1; j <= n && p; ++j, --p) {
        cout << i << " " << j << endl;
      }
    }
  }
}
