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