#include <bits/stdc++.h>
using namespace std;
const int N = 24 * 24;
int ans[N][2];
int main() {
  int n, p, test;
  scanf("%d", &test);
  while (test--) {
    scanf("%d%d", &n, &p);
    int cnt = 0;
    ans[cnt][0] = 1;
    ans[cnt++][1] = n;
    for (int i = 1; i <= n - 2; i++) {
      ans[cnt][0] = 1;
      ans[cnt++][1] = i + 1;
      ans[cnt][0] = n;
      ans[cnt++][1] = i + 1;
    }
    int rem = p + 3;
    for (int i = 2; i <= n - 2 && rem > 0; i++)
      for (int j = i + 1; j <= n - 1 && rem > 0; j++) {
        ans[cnt][0] = i;
        ans[cnt++][1] = j;
        rem--;
      }
    for (int i = 0; i < cnt; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}
