#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <typename T>
void __printer(const char* var_name, T&& val) {
  cerr << var_name << " = " << val << endl;
}
template <typename T, typename... Arguments>
void __printer(const char* arg_names, T&& val, Arguments&&... remaining_args) {
  const char* comma = strchr(arg_names + 1, ',');
  cerr.write(arg_names, comma - arg_names) << " = " << val << ", ";
  __printer(comma + 1, remaining_args...);
}
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int _ = 1;
  cin >> _;
  while (_--) {
    long long int n, k;
    cin >> n >> k;
    long long int c = 2 * n + k;
    for (long long int i = 1; i <= n; ++i) {
      for (long long int j = i + 1; j <= n; ++j) {
        if (i != j) {
          cout << i << " " << j << '\n';
          c--;
        }
        if (c == 0) break;
      }
      if (c == 0) break;
    }
  }
  return 0;
}
