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