#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
void solve() {
  int n, p;
  cin >> n >> p;
  int edges = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      cout << i << ' ' << j << '\n';
      edges++;
      if (edges == 2 * n + p) return;
    }
  }
}
int main(void) {
  int tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
