#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    int n, p;
    cin >> n >> p;
    vector<vector<int> > A(n, vector<int>(n));
    int x = 2 * n + p;
    for (int i = 0; i < n; i++) {
      if (A[i][(i + 1) % n] == 0) {
        A[i][(i + 1) % n] = 1;
        A[(i + 1) % n][i] = 1;
        cout << i + 1 << ' ' << (i + 1) % n + 1 << '\n';
        x--;
      }
    }
    for (int i = 0; i < n; i++) {
      if (A[i][(i + 2) % n] == 0) {
        A[i][(i + 2) % n] = 1;
        A[(i + 2) % n][i] = 1;
        cout << i + 1 << ' ' << (i + 2) % n + 1 << '\n';
        x--;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (x > 0 && i != j && A[i][j] == 0) {
          A[i][j] = 1;
          A[j][i] = 1;
          cout << i + 1 << ' ' << j + 1 << '\n';
          x--;
        }
      }
    }
  }
  return 0;
}
