#include <bits/stdc++.h>
using namespace std;
int n, p;
vector<int> a[25];
int sign[25][25];
int main() {
  int test, timer, j, i, now = 0;
  scanf("%d", &test);
  while (test--) {
    now++;
    timer = 2;
    scanf("%d%d", &n, &p);
    for (i = 0; i < n; i++) {
      a[i].clear();
      a[i].push_back((i + 1) % n);
      a[i].push_back((i + 2) % n);
    }
    while (p > 0) {
      timer++;
      for (i = 0; i < n; i++) {
        if (sign[i][(i + timer) % n] < now) {
          a[i].push_back((i + timer) % n);
          sign[i][(i + timer) % n] = now;
          sign[(i + timer) % n][i] = now;
          p--;
        }
        if (p == 0) break;
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < a[i].size(); j++) printf("%d %d\n", i + 1, a[i][j] + 1);
    }
  }
  return 0;
}
