#include <bits/stdc++.h>
using namespace std;
const int inf = ((1 << 30) - 1);
const long long linf = ((1ll << 62) - 1);
const int N = 100;
int n, p;
int a[N][N];
vector<pair<int, int> > ans;
void addEdge(int u, int v) {
  assert(!a[u][v] && !a[v][u]);
  ans.push_back(make_pair(u, v));
  a[u][v] = a[v][u] = 1;
}
bool check() {
  if (((int)(ans).size()) != 2 * n + p) return false;
  for (int i = 0; i < (1 << n); i++) {
    int maxCount = __builtin_popcount(i) + p;
    int curCount = 0;
    for (int j = 0; j < ((int)(ans).size()); j++)
      if ((i & (1 << ans[j].first)) && (i & (1 << ans[j].second))) curCount++;
    if (curCount > maxCount) return false;
  }
  return true;
}
void solve() {
  cin >> n >> p;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) a[i][j] = 0;
  ans.clear();
  for (int t = 1; t <= 2; t++)
    for (int i = 0; i < n; i++) addEdge(i, (i + t) % n);
  int np = p;
  for (int t = 3;; t++) {
    for (int i = 0; i < n; i++)
      if (np > 0) addEdge(i, (i + t) % n), np--;
    if (!np) break;
  }
  for (int i = 0; i < ((int)(ans).size()); i++)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) solve(), ({});
  return 0;
}
