#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, p;
  cin >> t;
  for (; t > 0; t--) {
    cin >> n >> p;
    int br = 0;
    for (int r = 1; r <= n; r++) {
      for (int i = 1; i <= n; i++) {
        cout << i << " " << (i + r - 1) % n + 1 << endl;
        br++;
        if (br == 2 * n + p) goto st;
      }
    }
  st:;
  }
  return 0;
}
