#include <bits/stdc++.h>
int main() {
  int n, t, i, j, p;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &p);
    int num = 0;
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++) {
        printf("%d %d\n", i, j);
        num++;
        if (num == 2 * n + p) break;
      }
      if (num == 2 * n + p) break;
    }
  }
}
