description: This is the easy version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved.
  
  A forest is an undirected graph without cycles (not necessarily connected).
  
  Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from 1 to n, and they would like to add edges to their forests such that: 
  
    * After adding edges, both of their graphs are still forests. 
    * They add the same edges. That is, if an edge (u, v) is added to Mocha's forest, then an edge (u, v) is added to Diana's forest, and vice versa. 
  
  
  
  Mocha and Diana want to know the maximum number of edges they can add, and which edges to add.
  
  Input
  
  The first line contains three integers n, m_1 and m_2 (1 ≤ n ≤ 1000, 0 ≤ m_1, m_2 < n) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest.
  
  Each of the next m_1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Mocha's forest.
  
  Each of the next m_2 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Diana's forest.
  
  Output
  
  The first line contains only one integer h, the maximum number of edges Mocha and Diana can add (in each forest).
  
  Each of the next h lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edge you add each time.
  
  If there are multiple correct answers, you can print any one of them.
  
  Examples
  
  Input
  
  
  3 2 2
  1 2
  2 3
  1 2
  1 3
  
  
  Output
  
  
  0
  
  
  Input
  
  
  5 3 2
  5 4
  2 1
  4 3
  4 3
  1 4
  
  
  Output
  
  
  1
  2 4
  
  
  Input
  
  
  8 1 2
  1 7
  2 6
  1 5
  
  
  Output
  
  
  5
  5 2
  2 3
  3 4
  4 7
  6 8
  
  Note
  
  In the first example, we cannot add any edge.
  
  In the second example, the initial forests are as follows.
  
  <image>
  
  We can add an edge (2, 4).
  
  <image>
solution: import java.io.*;
  import java.util.*;
  import static java.lang.System.in;
  import static java.lang.System.out;
  
  public class D {    
   
      public static int findSet(int s, int []parent){
          if(s == parent[s])
              return s;
          return parent[s] = findSet(parent[s], parent);
      }
      public static void unionSet(int a, int b, int []parent){
          a = findSet(a, parent);
          b = findSet(b, parent);
          if(a == b)
              return;
          parent[a] = b;
      }
  
      public static void main(String args[]) throws Exception {   
          Foster sc = new Foster();
          PrintWriter p = new PrintWriter(out);
          int n = sc.nextInt();
          int m1 = sc.nextInt(), m2 = sc.nextInt();
          int parentA[] = new int[n+1];
          int parentB[] = new int[n+1];
          for(int i = 0; i <= n; i++) {
              parentA[i] = i;
              parentB[i] = i;
          }
          for(int i = 0; i < m1; i++) {
              int u = sc.nextInt(), v = sc.nextInt();
              unionSet(u, v, parentA);
          }
          for(int i = 0; i < m2; i++) {
              int u = sc.nextInt(), v = sc.nextInt();
              unionSet(u, v, parentB);
          }
          ArrayList<Pair> arr = new ArrayList<>();
          for(int i = 1; i <= n; i++) {
              for(int j = i+1; j <= n; j++) {
                  if(i==j)    continue;
                  if(findSet(i, parentA) != findSet(j, parentA) && findSet(i, parentB) != findSet(j, parentB)) {
                      unionSet(i, j, parentA);
                      unionSet(i, j, parentB);
                      arr.add(new Pair(i, j));
                  }
              }
          }
          p.println(arr.size());
          for(int i = 0; i < arr.size(); i++) {
              p.println(arr.get(i).v + " " + arr.get(i).u);
          }
          p.close();
      }
      
      static class Pair{
          int u, v;
          public Pair(int u, int v) {
              this.u = u;
              this.v = v;
          }
      }
      static long[] sort(long a[]){
          ArrayList<Long> arr = new ArrayList<>();
          for(long i : a){
              arr.add(i);
          }
          Collections.sort(arr);
          for(int i = 0; i < arr.size(); i++){
              a[i] = arr.get(i);
          }
          return a;
      }
  
      static int[] sort(int a[]){
          ArrayList<Integer> arr = new ArrayList<>();
          for(int i : a){
              arr.add(i);
          }
          Collections.sort(arr);
          // Collections.reverse(arr);
          for(int i = 0; i < arr.size(); i++){
              a[i] = arr.get(i);
          }
          return a;
      }
      
  /*
   * Is that extra condition needed
   * Check overflow in pow function or in general
   * Check indices of read array functions
   * Think of an easier solution because the problems you solve are always easy
   * Check the iterator of loop
   */      
  
      static class Foster {
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          StringTokenizer st = new StringTokenizer("");
          String next() {
              while (!st.hasMoreTokens())
                  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());
          }
          int[] intArray(int n) {
              int arr[] = new int[n];
              for(int i = 0; i < n; i++) {
                  arr[i] = nextInt();
              }
              return arr;
          }
          long[] longArray(int n) {
              long arr[] = new long[n];
              for(int i = 0; i < n; i++) {
                  arr[i] = nextLong();
              }
              return arr;
          }
          static long pow(long... a) {
              long mod = Long.MAX_VALUE;
              if(a.length == 3)   mod = a[2];
              long res = 1;
              while(a[1] > 0) {
                  if((a[1] & 1) == 1)
                      res = (res * a[0]) % mod;
                  a[1] /= 2;
                  a[0] = (a[0] * a[0]) % mod;
              }
              return res;
          }
      }
  }