#include <bits/stdc++.h>
using namespace std;
int i, j, n, p, t;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> p;
    for (i = 1; i <= 5; i++)
      for (j = i + 1; j <= 5; j++) cout << i << ' ' << j << "\n";
    for (i = 6; i <= n; i++) cout << "1 " << i << "\n2 " << i << "\n";
    i = 3;
    while (p) {
      for (j = max(6, i + 1); j <= n; j++) {
        cout << i << ' ' << j << "\n";
        if (--p == 0) break;
      }
      i++;
    }
  }
  return 0;
}
