#include <bits/stdc++.h>
const long long MOD = 1000000007;
const double EPS = 1e-9;
using namespace std;
bool e[32][32];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(e, 1, sizeof(e));
    int n, p;
    cin >> n >> p;
    p += 2 * n;
    int rem = n * (n - 1) / 2 - p;
    int v = 0, d = 1;
    while (rem--) {
      if (!e[v][(v + d) % n]) rem++;
      e[v][(v + d) % n] = e[(v + d) % n][v] = false;
      v++;
      if (v == n) {
        v = 0;
        d++;
      }
    }
    for (int i = int(0); i <= int((n)-1); i++)
      for (int j = int(0); j <= int((i)-1); j++)
        if (e[i][j]) printf("%d %d\n", j + 1, i + 1);
  }
}
