#include <bits/stdc++.h>
using namespace std;
int g[25][25], n, p, i, T, j, k;
bool FLAG;
int main() {
  scanf("%d", &T);
  while (T--) {
    for (i = 1; i <= 24; i++)
      for (j = 1; j <= 24; j++) g[i][j] = 0;
    scanf("%d%d", &n, &p);
    for (i = 1; i <= 5; i++)
      for (j = i + 1; j <= 5; j++) g[i][j] = g[j][i] = 1;
    for (i = 6; i <= n; i++) g[i][1] = g[i][2] = g[1][i] = g[2][i] = 1;
    for (i = 1; i <= p; i++) {
      FLAG = false;
      for (j = 1; !FLAG && j <= n; j++)
        for (k = j + 1; !FLAG && k <= n; k++)
          if (!g[j][k]) {
            g[j][k] = g[k][j] = 1;
            FLAG = true;
          }
    }
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++)
        if (g[i][j]) cout << i << ' ' << j << endl;
    }
  }
  return 0;
}
