#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
int tot, from[Maxn], to[Maxn];
int T, n, p, m;
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> p;
    m = 2 * n + p;
    tot = 0;
    for (int i = 1; i <= n; i++) {
      tot++;
      from[tot] = i, to[tot] = i + 1;
      if (to[tot] > n) to[tot] -= n;
      tot++;
      from[tot] = i, to[tot] = i + 2;
      if (to[tot] > n) to[tot] -= n;
    }
    for (int d = 3, i = 1; p; p--, i++) {
      tot++;
      from[tot] = i, to[tot] = i + d;
      if (to[tot] > n) to[tot] -= n;
      if (i == n) d++, i = 0;
    }
    for (int i = 1; i <= tot; i++) printf("%d %d\n", from[i], to[i]);
  }
  return 0;
}
