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