#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
bool G[maxn][maxn];
int n, p;
void solve() {
  scanf("%d%d", &n, &p);
  memset(G, 0, sizeof(G));
  for (int(i) = (0); (i) <= ((n)-1); (i)++) {
    printf("%d %d\n", i + 1, (i + 1) % n + 1);
    printf("%d %d\n", i + 1, (i + 2) % n + 1);
    G[i][(i + 1) % n] = G[(i + 1) % n][i] = true;
    G[i][(i + 2) % n] = G[(i + 2) % n][i] = true;
  }
  for (int(i) = (0); (i) <= ((n)-1); (i)++)
    for (int(j) = (0); (j) <= ((i)-1); (j)++)
      if (!G[i][j] && p) {
        printf("%d %d\n", i + 1, j + 1);
        G[i][j] = G[j][i] = true;
        p--;
      }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
}
