#include <bits/stdc++.h>
bool vis[25][25];
int main() {
  int T, n, p, i, j, k;
  for (scanf("%d", &T); T--;) {
    scanf("%d %d", &n, &p);
    memset(vis, 0, sizeof(vis));
    for (i = 1; i <= n; i++) {
      j = i + 1;
      if (j > n) j -= n;
      k = j + 1;
      if (k > n) k -= n;
      printf("%d %d\n%d %d\n", i, j, i, k);
      vis[i][j] = vis[j][i] = 1;
      vis[i][k] = vis[k][i] = 1;
    }
    k = 0;
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++)
        if (!vis[i][j]) {
          if (k == p) break;
          printf("%d %d\n", i, j);
          vis[i][j] = vis[j][i] = 1;
          k++;
        }
      if (j <= n) break;
    }
  }
  return 0;
}
