#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int n, p;
int a[50][50];
int main() {
  int T, TT;
  scanf("%d", &T);
  for (TT = 0; TT < T; TT++) {
    int i, j;
    scanf("%d%d", &n, &p);
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) a[i][j] = 0;
    }
    for (i = 0; i < n; i++) {
      a[i][(i + 1) % n] = a[i][(i + 2) % n] = 1;
      a[(i + 1) % n][i] = a[(i + 2) % n][i] = 1;
    }
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (p == 0) break;
        if (a[i][j] == 0) {
          a[i][j] = a[j][i] = 1;
          p--;
        }
      }
      if (p == 0) break;
    }
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (a[i][j] == 1) printf("%d %d\n", i + 1, j + 1);
      }
    }
  }
  return 0;
}
