#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int INF = (1LL << 29);
using namespace std;
template <typename T>
string toString(T t) {
  stringstream ss;
  ss << t;
  return ss.str();
}
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int n, p;
    cin >> n >> p;
    set<pair<int, int> > edges;
    for (int i = 0; i < n; i++) {
      edges.insert({i, (i + 1) % n});
      edges.insert({i, (i - 1 + n) % n});
      edges.insert({i, (i + 2) % n});
      edges.insert({i, (i - 2 + n) % n});
    }
    set<pair<int, int> > out;
    for (auto e : edges) {
      if (out.count(e) == 0 && out.count({e.second, e.first}) == 0)
        out.insert(e);
    }
    for (int i = 0; i < n && p; i++)
      for (int j = 0; j < n && p; j++) {
        if (i != j)
          if (out.count({i, j}) == 0 && out.count({j, i}) == 0) {
            out.insert({i, j});
            p--;
          }
      }
    for (auto e : out) {
      cout << e.first + 1 << " " << e.second + 1 << endl;
    }
  }
  return 0;
}
