#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
void solve() {
  int n, p;
  cin >> n >> p;
  int adj[n][n];
  memset(adj, 0, sizeof(adj));
  int orig = 2 * n;
  for (ll i = 0; i < (n); i++) {
    if (orig == 0) break;
    for (int j = i + 1; j < n; j++) {
      if (orig == 0) break;
      adj[i][j] = 1;
      adj[j][i] = 1;
      orig--;
    }
  }
  for (ll i = 0; i < (n); i++) {
    if (p == 0) break;
    for (int j = i + 1; j < n; j++) {
      if (p == 0) break;
      if (adj[i][j] == 0) {
        p--;
        adj[i][j] = 1;
        adj[j][i] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (adj[i][j] == 1) {
        cout << i + 1 << " " << j + 1 << '\n';
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
