#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[35][35];
  memset(a, 0, sizeof(a));
  int tot = 2 * n + m;
  int ind[35];
  memset(ind, 0, sizeof(ind));
  for (int i = 1; i <= n && tot; i++)
    for (int j = 1; i + j <= n && tot; j++) {
      a[j][i + j] = 1;
      tot--;
    }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (a[i][j]) cout << i << " " << j << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
