#include <bits/stdc++.h>
using namespace std;
int n, p;
int mp[1000][1000];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int m = 2 * n + p;
    memset(mp, 0, sizeof(mp));
    cin >> n >> p;
    for (int i = 1; i < n; i++) mp[i][i + 1] = 1;
    m = 2 * n + p;
    m = m - (n - 1);
    for (int i = 2; i < n; i++) {
      if (m == 0) break;
      for (int j = 1; j + i <= n; j++) {
        mp[j][j + i] = 1;
        m--;
        if (m == 0) break;
      }
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (mp[i][j]) cout << i << " " << j << endl;
  }
  return 0;
}
