#include <bits/stdc++.h>
#pragma comment(linker, "/stack:32000000")
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
void solve() {
  int n, p;
  scanf("%d%d", &n, &p);
  vector<vector<int> > a(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int add = -2; add <= 2; ++add) {
      if (add == 0) continue;
      int to = (i + add + n) % n;
      a[i][to] = 1;
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < i; ++j) {
      if (p == 0) break;
      if (a[i][j] == 0) a[i][j] = a[j][i] = 1, --p;
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < i; ++j)
      if (a[i][j]) printf("%d %d\n", j + 1, i + 1);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
