#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = 1e-9;
const int maxn = (int)110;
int a[maxn][maxn];
int main() {
  int tn;
  scanf("%d", &tn);
  while (tn-- > 0) {
    memset(a, 0, sizeof a);
    int n, p;
    scanf("%d%d", &n, &p);
    for (int i = 0; (i) < (n); ++i) a[i][i] = 1;
    for (int i = 0; (i) < (n); ++i) {
      int j = (i + 1) % n;
      a[i][j] = 1;
      a[j][i] = 1;
      printf("%d %d\n", i + 1, j + 1);
    }
    for (int i = 0; (i) < (n); ++i) {
      int j = (i + 2) % n;
      a[i][j] = 1;
      a[j][i] = 1;
      printf("%d %d\n", i + 1, j + 1);
    }
    int x = 0, y = 0;
    for (int i = 0; (i) < (p); ++i) {
      while (a[x][y]) {
        y += 1;
        if (y == n) x += 1, y = 0;
      }
      a[x][y] = 1;
      a[y][x] = 1;
      printf("%d %d\n", x + 1, y + 1);
    }
  }
  return 0;
}
