#include <bits/stdc++.h>
using namespace std;
int has[25][25];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(has, 0, sizeof(has));
    int n, p;
    cin >> n >> p;
    for (long long i = 0; i < (n); i++)
      has[i][(i + 1) % n] = has[(i + 1) % n][i] = 1;
    for (long long i = 0; i < (n); i++)
      has[i][(i + 2) % n] = has[(i + 2) % n][i] = 1;
    int k = 3;
    while (p > 0) {
      int j = 0;
      while (p > 0 && has[j][(j + k) % n] == 0) {
        has[j][(j + k) % n] = has[(j + k) % n][j] = 1;
        j = (j + 1) % n;
        p--;
      }
      k++;
    }
    for (long long i = 0; i < (n); i++)
      for (long long j = (i + 1); j <= (n - 1); j++)
        if (has[i][j]) cout << i + 1 << " " << j + 1 << endl;
  }
}
