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