#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9) + 9;
const int N = 20100;
void solve() {
  int n, p;
  cin >> n >> p;
  vector<vector<int>> g(n + 1, vector<int>(n + 1, 0));
  int e = 2 * n + p;
  for (int i = 1; e && i < n; i++) {
    for (int v = 1; e && v + i <= n; v++) {
      g[v][v + i] = 1;
      e--;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (g[i][j]) {
        cout << i << " " << j << endl;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}
