#include <bits/stdc++.h>
using namespace std;
void f(int n, int p) {
  bool mm[n][n];
  memset(mm, 0, sizeof(mm));
  for (int i = 0; i < n; ++i) mm[i][(i + 1) % n] = mm[(i + 1) % n][i] = 1;
  for (int i = 0; i < n; ++i) mm[i][(i + 2) % n] = mm[(i + 2) % n][i] = 1;
  for (int i = 0; i < n && p > 0; ++i)
    for (int j = 0; j < n && p > 0; ++j) {
      if (i == j) continue;
      if (mm[i][j] == 0) mm[j][i] = mm[i][j] = 1, --p;
    }
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      if (mm[i][j] == 1) cout << i + 1 << ' ' << j + 1 << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n, p;
    cin >> n >> p;
    f(n, p);
  }
  return 0;
}
