#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > E;
int n, p;
bool adj[25][25];
void addEdge(int u, int v) {
  if (int(E.size()) < 2 * n + p) {
    if (!adj[u][v])
      adj[u][v] = adj[v][u] = true, E.push_back(pair<int, int>(u, v));
  }
}
int main() {
  int nT;
  cin >> nT;
  while (nT--) {
    cin >> n >> p;
    E.clear();
    memset(adj, false, sizeof adj);
    for (int u = 1; u <= n; u++) {
      int v1 = u + 1, v2 = u + 2;
      if (v1 > n) v1 -= n;
      if (v2 > n) v2 -= n;
      addEdge(u, v1);
      addEdge(u, v2);
    }
    for (int u = 1; u <= n && int(E.size()) < 2 * n + p; u++)
      for (int v = u + 1; v <= n && int(E.size()) < 2 * n + p; v++) {
        if (adj[u][v]) continue;
        addEdge(u, v);
      }
    for (int i = 0; i < int(E.size()); i++)
      cout << E[i].first << ' ' << E[i].second << '\n';
  }
  return 0;
}
