description: Lord Omkar would like to have a tree with n nodes (3 ≤ n ≤ 10^5) and has asked his disciples to construct the tree. However, Lord Omkar has created m (1 ≤ m < n) restrictions to ensure that the tree will be as heavenly as possible. 
  
  A tree with n nodes is an connected undirected graph with n nodes and n-1 edges. Note that for any two nodes, there is exactly one simple path between them, where a simple path is a path between two nodes that does not contain any node more than once.
  
  Here is an example of a tree: 
  
  <image>
  
  A restriction consists of 3 pairwise distinct integers, a, b, and c (1 ≤ a,b,c ≤ n). It signifies that node b cannot lie on the simple path between node a and node c. 
  
  Can you help Lord Omkar and become his most trusted disciple? You will need to find heavenly trees for multiple sets of restrictions. It can be shown that a heavenly tree will always exist for any set of restrictions under the given constraints.
  
  Input
  
  Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.
  
  The first line of each test case contains two integers, n and m (3 ≤ n ≤ 10^5, 1 ≤ m < n), representing the size of the tree and the number of restrictions.
  
  The i-th of the next m lines contains three integers a_i, b_i, c_i (1 ≤ a_i, b_i, c_i ≤ n, a, b, c are distinct), signifying that node b_i cannot lie on the simple path between nodes a_i and c_i. 
  
  It is guaranteed that the sum of n across all test cases will not exceed 10^5.
  
  Output
  
  For each test case, output n-1 lines representing the n-1 edges in the tree. On each line, output two integers u and v (1 ≤ u, v ≤ n, u ≠ v) signifying that there is an edge between nodes u and v. Given edges have to form a tree that satisfies Omkar's restrictions.
  
  Example
  
  Input
  
  
  2
  7 4
  1 2 3
  3 4 5
  5 6 7
  6 5 4
  5 3
  1 2 3
  2 3 4
  3 4 5
  
  
  Output
  
  
  1 2
  1 3
  3 5
  3 4
  2 7
  7 6
  5 1
  1 3
  3 2
  2 4
  
  Note
  
  The output of the first sample case corresponds to the following tree: 
  
  <image> For the first restriction, the simple path between 1 and 3 is 1, 3, which doesn't contain 2. The simple path between 3 and 5 is 3, 5, which doesn't contain 4. The simple path between 5 and 7 is 5, 3, 1, 2, 7, which doesn't contain 6. The simple path between 6 and 4 is 6, 7, 2, 1, 3, 4, which doesn't contain 5. Thus, this tree meets all of the restrictions.
  
  The output of the second sample case corresponds to the following tree: 
  
  <image>
solution:  //package eround101;
  
  import java.util.*;
  import java.io.*;
  import java.lang.*;
  import java.util.StringTokenizer;
  
  public class Solution {
  
      static HritikScanner sc = new HritikScanner();
      static PrintWriter pw = new PrintWriter(System.out, true);
      final static int MOD = 1000000007;
      static StringBuilder sb = new StringBuilder();
  
      public static void main(String[] args) {
  
          int t = ni();
          while (t-- > 0) {
              solve();
          }
      }
  
      static void solve() {
          int n = ni();
          int m = ni();
          HashSet<Integer> set = new HashSet<>();
          for (int i = 0; i < m; i++) {
              int a = ni();
              int b = ni();
              int c = ni();
              set.add(b);
          }
          int root = -1;
          for(int i = 1; i<= n; i++)
          {
              if(!set.contains(i))
              {
                  root = i;
                  break;
              }
          }
          for(int i = 1; i<= n; i++)
          {
              if(i == root)
                  continue;
              pl(root+" "+i);
          }
          
  
      }
  
      /////////////////////////////////////////////////////////////////////////////////
      static class FenwickTree { // Binary Index Tree
  
          int[] tree;
          static int size;
  
          public FenwickTree(int size) {
              this.size = size;
              tree = new int[size + 5];
          }
  
          public void add(int i, int val) {
              while (i <= size) {
                  tree[i] += val;
                  i += i & -i;  // adding the decimal value of the last set bit.
              }
          }
  
          public int sum(int i) {
              int res = 0;
              while (i >= 1) {
                  res += tree[i];
                  i -= i & -i; // deleting the last set bit
              }
              return res;
          }
  
          public int sum(int l, int r) {
              return sum(r) - sum(l - 1);
          }
      }
  
      /////////////////////////////////////////////////////////////////////////////////
      static int[] nextIntArray(int n) {
          int[] arr = new int[n];
          int i = 0;
          while (i < n) {
              arr[i++] = ni();
          }
          return arr;
      }
  
      static long[] nextLongArray(int n) {
          long[] arr = new long[n];
          int i = 0;
          while (i < n) {
              arr[i++] = nl();
          }
          return arr;
      }
  
      static int[] nextIntArray1(int n) {
          int[] arr = new int[n + 1];
          int i = 1;
          while (i <= n) {
              arr[i++] = ni();
          }
          return arr;
      }
  
      /////////////////////////////////////////////////////////////////////////////////
      static int ni() {
          return sc.nextInt();
      }
  
      static long nl() {
          return sc.nextLong();
      }
  
      static double nd() {
          return sc.nextDouble();
      }
  
      /////////////////////////////////////////////////////////////////////////////////
      static void pl() {
          pw.println();
      }
  
      static void p(Object o) {
          pw.print(o + " ");
      }
  
      static void pl(Object o) {
          pw.println(o);
      }
  
      static void psb(StringBuilder sb) {
          pw.print(sb);
      }
  
      static void pa(Object arr[]) {
          for (Object o : arr) {
              p(o);
          }
          pl();
      }
  
      static void pa(int arr[]) {
          for (int o : arr) {
              p(o);
          }
          pl();
      }
  
      static void pa(long arr[]) {
          for (long o : arr) {
              p(o);
          }
          pl();
      }
  
      static void pa(double arr[]) {
          for (double o : arr) {
              p(o);
          }
          pl();
      }
  
      static void pa(char arr[]) {
          for (char o : arr) {
              p(o);
          }
          pl();
      }
  
      static void pa(List list) {
          for (Object o : list) {
              p(o);
          }
          pl();
      }
  
      static void pa(Object[][] arr) {
  
          for (int i = 0; i < arr.length; ++i) {
              for (Object o : arr[i]) {
                  p(o);
              }
              pl();
          }
      }
  
      static void pa(int[][] arr) {
          for (int i = 0; i < arr.length; ++i) {
              for (int o : arr[i]) {
                  p(o);
              }
              pl();
          }
      }
  
      static void pa(long[][] arr) {
          for (int i = 0; i < arr.length; ++i) {
              for (long o : arr[i]) {
                  p(o);
              }
              pl();
          }
      }
  
      static void pa(char[][] arr) {
          for (int i = 0; i < arr.length; ++i) {
              for (char o : arr[i]) {
                  p(o);
              }
              pl();
          }
      }
  
      static void pa(double[][] arr) {
          for (int i = 0; i < arr.length; ++i) {
              for (double o : arr[i]) {
                  p(o);
              }
              pl();
          }
      }
  
  /////////////////////////////////////////////////////////////////////////////////
      static void print(Object s) {
          System.out.println(s);
      }
  
      /////////////////////////////////////////////////////////////////////////////////
      //-----------HritikScanner class for faster input----------//
      static class HritikScanner {
  
          BufferedReader br;
          StringTokenizer st;
  
          public HritikScanner() {
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
      //////////////////////////////////////////////////////////////////
      public static class Pair implements Comparable<Pair> {
  
          int num, row, col;
  
          Pair(int num, int row, int col) {
              this.num = num;
              this.row = row;
              this.col = col;
          }
  
          public int get1() {
              return num;
          }
  
          public int get2() {
              return row;
          }
  
          public int compareTo(Pair A) {
              return this.num - A.num;
          }
  
          public String toString() {
              return num + " " + row + " " + col;
          }
      }
  
      //////////////////////////////////////////////////////////////////
      // Function to return gcd of a and b time complexity O(log(a+b))
      static long gcd(long a, long b) {
          if (a == 0) {
              return b;
          }
          return gcd(b % a, a);
      }
  
      // method to return LCM of two numbers 
      static long lcm(int a, int b) {
          return (a / gcd(a, b)) * b;
      }
  
      //////////////////////////////////////////////////////////////////
      static boolean isPrime(long n) {
          // Corner cases 
          if (n <= 1) {
              return false;
          }
          if (n <= 3) {
              return true;
          }
  
          // This is checked so that we can skip  
          // middle five numbers in below loop 
          if (n % 2 == 0 || n % 3 == 0) {
              return false;
          }
  
          for (long i = 5; i * i <= n; i = i + 6) {
              if (n % i == 0 || n % (i + 2) == 0) {
                  return false;
              }
          }
  
          return true;
      }
      //////////////////////////////////////////////////////////////////
  
      static boolean isPowerOfTwo(long n) {
          if (n == 0) {
              return false;
          }
  
          return (long) (Math.ceil((Math.log(n) / Math.log(2))))
                  == (long) (Math.floor(((Math.log(n) / Math.log(2)))));
      }
  
      public static long getFact(int n) {
          long ans = 1;
          while (n > 0) {
              ans *= n;
              ans %= MOD;
              n--;
          }
          return ans;
      }
  
      public static long pow(long n, int pow) {
          if (pow == 0) {
              return 1;
          }
          long temp = pow(n, pow / 2) % MOD;
          temp *= temp;
          temp %= MOD;
          if (pow % 2 == 1) {
              temp *= n;
          }
          temp %= MOD;
          return temp;
  
      }
  
      public static long nCr(int n, int r) {
          long ans = 1;
          int temp = n - r;
          while (n > temp) {
              ans *= n;
              ans %= MOD;
              n--;
          }
          ans *= pow(getFact(r) % MOD, MOD - 2) % MOD;
          ans %= MOD;
          return ans;
      }
  
      //////////////////////////////////////////////////////////////////
      // method returns Nth power of A 
      static double nthRoot(int A, int N) {
  
          // intially guessing a random number between 
          // 0 and 9 
          double xPre = Math.random() % 10;
  
          // smaller eps, denotes more accuracy 
          double eps = 0.001;
  
          // initializing difference between two 
          // roots by INT_MAX 
          double delX = 2147483647;
  
          // xK denotes current value of x 
          double xK = 0.0;
  
          // loop untill we reach desired accuracy 
          while (delX > eps) {
              // calculating current value from previous 
              // value by newton's method 
              xK = ((N - 1.0) * xPre
                      + (double) A / Math.pow(xPre, N - 1)) / (double) N;
              delX = Math.abs(xK - xPre);
              xPre = xK;
          }
  
          return xK;
      }
  
  }
  