#include <bits/stdc++.h>
using namespace std;
int nextint() {
  int _;
  scanf("%d", &_);
  return _;
}
long long nextll() {
  long long _;
  scanf("%I64d", &_);
  return _;
}
string nextstring() {
  string _;
  cin >> _;
  return _;
}
vector<int> sz;
int g[32][32];
class vertex {
 public:
  vertex(int id = 0) : id(id) {}
  int id;
};
bool operator<(const vertex &a, const vertex &b) {
  if (sz[a.id] != sz[b.id]) return sz[a.id] < sz[b.id];
  return a.id < b.id;
}
int main() {
  int t = nextint();
  while (t--) {
    int n = nextint();
    int p = nextint();
    sz = vector<int>(n);
    memset(g, 0, sizeof g);
    set<vertex> s;
    for (int i = 0; i < n; i++) {
      s.insert(vertex(i));
      g[i][i] = 1;
      sz[i]++;
    }
    int cnt = 2 * n + p;
    while (cnt--) {
      int i = s.begin()->id, j = -1;
      s.erase(s.begin());
      for (set<vertex>::iterator it = s.begin(); it != s.end(); it++) {
        if (g[i][it->id] == 0) {
          j = it->id;
          s.erase(it);
          break;
        }
      }
      g[i][j] = g[j][i] = 1;
      sz[i]++;
      sz[j]++;
      s.insert(vertex(i));
      s.insert(vertex(j));
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (g[i][j]) {
          printf("%d %d\n", i + 1, j + 1);
        }
      }
    }
  }
  return 0;
}
