#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, p;
    scanf("%d%d", &n, &p);
    p += 2 * n;
    set<pair<int, int> > E;
    E.insert(make_pair(1, 2));
    for (int v = 3; v <= n; ++v) {
      E.insert(make_pair(v - 1, v));
      E.insert(make_pair(v - 2, v));
    }
    for (int v = 1; v <= n; ++v) {
      for (int w = v + 1; w <= n; ++w) {
        E.insert(make_pair(v, w));
        if (((int)((E).size())) == p) {
          break;
        }
      }
      if (((int)((E).size())) == p) {
        break;
      }
    }
    for (const pair<int, int> e : E) {
      printf("%d %d\n", e.first, e.second);
    }
  }
  return 0;
}
