#include <bits/stdc++.h>
using namespace std;
bool f[111][111];
int main() {
  int test, n, p, ni, nj;
  cin >> test;
  for (int ntest = 1; ntest <= test; ntest++) {
    scanf("%d%d", &n, &p);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) f[i][j] = false;
    for (int i = 1; i <= n; i++) {
      ni = i;
      nj = ((i == n) ? 1 : i + 1);
      f[ni][nj] = true;
      f[nj][ni] = true;
    }
    for (int i = 1; i <= n; i++) {
      ni = i;
      nj = ((i + 2 > n) ? i + 2 - n : i + 2);
      f[ni][nj] = true;
      f[nj][ni] = true;
    }
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        if (p && (!f[i][j])) {
          f[i][j] = true;
          p--;
        }
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        if (f[i][j]) printf("%d %d\n", i, j);
  }
  return 0;
}
