text: #include <fstream>
  #include <iostream>
  #include <vector>
  #include <bitset>
  #include <string.h>
  #include <algorithm>
  #include <iomanip>
  #include <math.h>
  #include <time.h>
  #include <stdlib.h>
  #include <set>
  #include <map>
  #include <string>
  #include <queue>
  #include <deque>
  
  using namespace std;
  
  const char infile[] = "input.in";
  const char outfile[] = "output.out";
  
  ifstream fin(infile);
  ofstream fout(outfile);
  
  const int MAXN = 100005;
  const int oo = 0x3f3f3f3f;
  
  typedef vector<int> Graph[MAXN];
  typedef vector<int> :: iterator It;
  
  const inline int min(const int &a, const int &b) { if( a > b ) return b;   return a; }
  const inline int max(const int &a, const int &b) { if( a < b ) return b;   return a; }
  const inline void Get_min(int &a, const int b)    { if( a > b ) a = b; }
  const inline void Get_max(int &a, const int b)    { if( a < b ) a = b; }
  
  int T, N, P;
  
  int main() {
      cin.sync_with_stdio(false);
      #ifndef ONLINE_JUDGE
      freopen(infile, "r", stdin);
      freopen(outfile, "w", stdout);
      #endif
      cin >> T;
      for(int test = 1 ; test <= T ; ++ test) {
          cin >> N >> P;
          int edges = 0;
          for(int i = 1 ; i <= N && edges < 2 * N + P ; ++ i)
              for(int j = i + 1 ; j <= N && edges < 2 * N + P ; ++ j) {
                  cout << i << ' ' << j << '\n';
                  ++ edges;
              }
      }
      fin.close();
      fout.close();
      return 0;
  }
  