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