#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::map;
using std::max;
using std::min;
using std::multiset;
using std::pair;
using std::queue;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::vector;
int main() {
  int t;
  cin >> t;
  for (int ooo = 0; ooo < t; ooo++) {
    int n, p;
    cin >> n >> p;
    p += n * 2;
    int data[50][50] = {
        0,
    };
    int i = 0;
    while (p > 0) {
      if (p == 0) {
        break;
      }
      p--;
      for (int j = i + 1; j < i + n + n; j++) {
        int to = j % n;
        if (data[i][to] == 0) {
          data[i][to] = data[to][i] = 1;
          break;
        }
      }
      i++;
      i %= n;
    }
    for (int x = 0; x < n; x++) {
      for (int y = x + 1; y < n; y++) {
        if (data[x][y]) {
          cout << x + 1 << " " << y + 1 << endl;
        }
      }
    }
  }
  return 0;
}
