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