#include <bits/stdc++.h>
bool e[25][25];
using namespace std;
int main() {
  int t, n, p;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &p);
    memset(e, 0, sizeof e);
    for (int i = 1; i <= n; i++) e[i][i + 1] = e[i][i + 2] = true;
    e[1][n] = e[2][n] = e[1][n - 1] = true;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        if (e[i][j])
          printf("%d %d\n", i, j);
        else if (p) {
          printf("%d %d\n", i, j);
          p--;
        }
  }
  return 0;
}
