#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline string intToString(T x) {
  ostringstream q;
  q << x;
  return q.str();
}
template <typename T>
inline T myPow(T x, T n, T MOD) {
  T res = 1;
  while (n > 0) {
    if (n & 1) {
      res = 1ll * res * x % MOD;
    }
    x = 1ll * x * x % MOD;
    n /= 2;
  }
  return res;
}
template <typename T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while ((a > 0) && (b > 0)) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
int a[111][111];
int main() {
  int tests;
  cin >> tests;
  for (int i = 0; i < tests; ++i) {
    int n, p;
    cin >> n >> p;
    memset(a, 0, sizeof a);
    int res = 0;
    for (int i = 0; i < n; ++i) {
      int next = (i + 1) % n;
      a[i][next] = 1;
      a[next][i] = 1;
      next = (next + 1) % n;
      a[i][next] = 1;
      a[next][i] = 1;
      res++;
      res++;
    }
    int step = 3;
    while (res < 2 * n + p) {
      for (int i = 0; i < n; ++i) {
        int next = (i + step) % n;
        if (a[i][next] == 0) {
          a[i][next] = 1;
          a[next][i] = 1;
          res++;
        }
        if (res == 2 * n + p) break;
      }
      step++;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < i; ++j) {
        if (a[i][j]) cout << j + 1 << " " << i + 1 << endl;
      }
    }
  }
}
