#include <bits/stdc++.h>
using namespace std;
const int maxN = 50;
bool e[maxN][maxN];
int main() {
  int t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < maxN; i++)
      for (int j = 0; j < maxN; j++) e[i][j] = 0;
    int n, p, m;
    cin >> n >> p;
    m = 2 * n + p;
    for (int i = 0; m && i + 5 <= n; i += 5)
      for (int j = i; m && j < i + 5; j++)
        for (int k = j + 1; m && k < min(i + 5, n); k++) {
          cout << j + 1 << " " << k + 1 << endl;
          e[j][k] = e[k][j] = 1;
          m--;
        }
    cerr << "here!" << endl;
    for (int i = n / 5 * 5; m && i < n; i++)
      for (int j = 3; m && j < 5; j++) {
        cout << i + 1 << " " << j + 1 << endl;
        m--;
        e[i][j] = e[j][i] = 1;
      }
    cerr << m << endl;
    while (m) {
      bool fl = 0;
      for (int i = 0; m && i < n; i++)
        for (int j = i + 1; m && j < n; j++)
          if (i != j && !e[i][j]) {
            e[i][j] = e[j][i] = 1;
            cout << i + 1 << " " << j + 1 << endl;
            m--;
            i += 5;
            i = i / 5 * 5;
            break;
          }
    }
  }
}
