#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t-- > 0) {
    static int aa[24][24];
    int n, p, i, j;
    scanf("%d%d", &n, &p);
    memset(aa, 0, sizeof aa);
    for (i = 0; i < n; i++) {
      int i1 = (i + 1) % n;
      int i2 = (i + 2) % n;
      aa[i][i1] = aa[i1][i] = 1;
      aa[i][i2] = aa[i2][i] = 1;
    }
    for (i = 0; i < n; i++)
      for (j = i + 1; j < n; j++)
        if (p > 0 && !aa[i][j] && !aa[j][i]) {
          aa[i][j] = aa[j][i] = 1;
          p--;
        }
    for (i = 0; i < n; i++)
      for (j = i + 1; j < n; j++)
        if (aa[i][j]) printf("%d %d\n", i + 1, j + 1);
  }
  return 0;
}
