#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
  int T;
  cin >> T;
  for (int t = 1; t <= T; t += 1) {
    int n, p;
    cin >> n >> p;
    p += 2 * n;
    int e = 0;
    for (int i = 1; i <= n and e < p; i += 1) {
      for (int j = i + 1; j <= n and e < p; j += 1) {
        cout << i << ' ' << j << '\n';
        e += 1;
      }
    }
  }
  return 0;
}
