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