#include <bits/stdc++.h>
using namespace std;
bool G[25][25];
int P;
int N;
struct SB {
  vector<int> nodes;
  int numEdges;
  bool addEdge() {
    if (numEdges >= 2 * nodes.size() + P) return false;
    for (int i = 0; i < nodes.size(); i++) {
      int u = nodes[i];
      for (int j = 0; j < nodes.size(); j++) {
        int v = nodes[j];
        if (u != v and !G[i][j]) {
          G[i][j] = true;
          G[j][i] = true;
          numEdges++;
          return true;
        }
      }
    }
    return false;
  }
  SB() {
    nodes.clear();
    numEdges = 0;
  }
  SB(int k) {
    nodes.clear();
    nodes.push_back(k);
    numEdges = 0;
  }
};
SB addSB(SB A, SB B) {
  SB ans;
  ans.numEdges = A.numEdges + B.numEdges;
  vector<int> tmp;
  for (int i = 0; i < A.nodes.size(); i++) {
    tmp.push_back(A.nodes[i]);
  }
  for (int i = 0; i < B.nodes.size(); i++) {
    tmp.push_back(B.nodes[i]);
  }
  ans.nodes = tmp;
  return ans;
}
vector<pair<vector<int>, int> > B;
int main() {
  int T;
  scanf("%d\n", &T);
  while (T--) {
    scanf("%d %d\n", &N, &P);
    deque<SB> Q;
    memset(G, false, sizeof G);
    for (int i = 0; i < N; i++) {
      Q.push_front(SB(i));
    }
    bool conectarTodo = false;
    for (int e = 1; true; e++) {
      SB x = Q.front();
      Q.pop_front();
      if (x.addEdge()) {
        Q.push_front(x);
      } else {
        SB y = Q.front();
        Q.pop_front();
        if (y.addEdge()) {
          Q.push_back(x);
          Q.push_front(y);
        } else {
          SB z = addSB(x, y);
          Q.push_front(z);
          e--;
        }
      }
      if (e + Q.size() - 1 == 2 * N + P) {
        conectarTodo = true;
        break;
      }
    }
    if (conectarTodo) {
      vector<SB> myB;
      while (!Q.empty()) {
        myB.push_back(Q.front());
        Q.pop_front();
      }
      for (int i = 1; i < myB.size(); i++) {
        int x = myB[i - 1].nodes[0];
        int y = myB[i].nodes[0];
        G[x][y] = true;
        G[y][x] = true;
      }
    }
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (G[i][j]) {
          printf("%d %d\n", i + 1, j + 1);
        }
      }
    }
  }
  return 0;
}
