#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
int mtr[30][30];
vector<int> pr;
bool prov(vector<int> v, int p) {
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      if (mtr[v[i]][v[j]]) cnt++;
    }
  }
  return cnt > (v.size() * 2 + p);
}
bool flag = false;
void perebor(int n, int p, int v) {
  if (v == n) {
    flag |= prov(pr, p);
    return;
  }
  pr.push_back(v);
  perebor(n, p, v + 1);
  pr.pop_back();
  perebor(n, p, v + 1);
}
int main() {
  int t;
  cin >> t;
  while (t) {
    t--;
    int n, p;
    cin >> n >> p;
    memset(mtr, 0, sizeof(mtr));
    for (int i = 0; i < n; i++) {
      mtr[i][(i + 1) % n] = 1;
      mtr[(i + 1) % n][i] = 1;
    }
    if (n % 2) {
      for (int i = 0; i < n; i++) {
        mtr[(2 * i) % n][(2 * (i + 1)) % n] = 1;
        mtr[(2 * (i + 1)) % n][(2 * i) % n] = 1;
      }
    } else {
      for (int i = 0; i < n; i += 2) {
        mtr[i][(i + 2) % n] = 1;
        mtr[(i + 2) % n][i] = 1;
      }
      for (int i = 1; i < n; i += 2) {
        mtr[i][(i + 2) % n] = 1;
        mtr[(i + 2) % n][i] = 1;
      }
    }
    for (int i = 0; i < n; i++) {
      if (p == 0) break;
      for (int j = i + 1; j < n; j++) {
        if (p == 0) break;
        if (mtr[i][j] == 0) {
          mtr[i][j] = mtr[j][i] = 1;
          p--;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (mtr[i][j]) {
          cout << i + 1 << " " << j + 1 << endl;
        }
      }
    }
  }
  return 0;
}
