#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
bool setmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  } else
    return false;
}
bool g[99][99];
int n, p;
int main() {
  int cs;
  cin >> cs;
  while (cs--) {
    cin >> n >> p;
    memset(g, false, sizeof(g));
    for (int i = (int)(1); i <= (int)(n); ++i) {
      int j = i;
      (j %= n) += 1;
      g[i][j] = g[j][i] = true;
      (j %= n) += 1;
      g[i][j] = g[j][i] = true;
    }
    for (int i = (int)(1); i <= (int)(n); ++i)
      for (int j = (int)(1); j <= (int)(n); ++j)
        if (i != j && !g[i][j] && p > 0) {
          --p;
          g[i][j] = g[j][i] = true;
        }
    for (int i = (int)(1); i <= (int)(n); ++i)
      for (int j = (int)(i); j <= (int)(n); ++j)
        if (g[i][j]) cout << i << " " << j << endl;
  }
  return 0;
}
