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.util.*;import java.io.*;import java.math.*;
  public class CF1559D
  {
      static boolean memory = true;
      static long mod = 998244353;
      static long MOD = 1000000007; 
      
      static void ruffleSort(int[] a) {
          int n = a.length;
          ArrayList<Integer> lst = new ArrayList<>();
          for(int i : a)
              lst.add(i);
          Collections.sort(lst);
          for(int i = 0; i < n; i++)
              a[i] = lst.get(i);
      }
  
      static void ruffleSort(long[] a) {
          int n = a.length; 
          ArrayList<Long> lst = new ArrayList<>();
          for(long i : a)
              lst.add(i);
          Collections.sort(lst);
          for(int i = 0; i < n; i++)
              a[i] = lst.get(i);
      }
  
      static int[] parent1;
      static int[] rank1;
      static int[] parent2;
      static int[] rank2;
  
      public static void process()throws IOException
      {
          int n = ni(), m1 = ni(), m2 = ni();
          parent1 = new int[n+1];
          rank1 = new int[n+1];
          parent2 = new int[n+1];
          rank2 = new int[n+1];
          for(int i = 1; i <= n; i++){
              make_set(i);
          }
          for(int i = 1; i <= m1+m2; i++){
              int u = ni(), v = ni();
              if(i > m1)
                  union_sets2(u, v);
              else
                  union_sets1(u, v);
          }
          int cnt = 0;
          ArrayList<Node> list = new ArrayList<>();
          for(int i = 1; i < n; i++){
              for(int j = i+1; j <= n; j++){
                  if(find_set1(i) == find_set1(j) || find_set2(i) == find_set2(j))
                      continue;
                  cnt++;
                  list.add(new Node(i, j));
                  union_sets1(i, j);
                  union_sets2(i, j);
                  break;
              }
          }
          pn(cnt);
          for(int i = 0; i < cnt; i++)
              pn(list.get(i).a+" "+list.get(i).b);
      }
  
      static void make_set(int v) {
          parent1[v] = v;
          parent2[v] = v;
      }
  
      static int find_set1(int v){
          if(v == parent1[v])
              return v;       
          return parent1[v] = find_set1(parent1[v]);
      }
  
      static int find_set2(int v){
          if(v == parent2[v])
              return v;       
          return parent2[v] = find_set2(parent2[v]);
      }
  
      static void union_sets1(int a, int b) {
          a = find_set1(a);
          b = find_set1(b);
          if (a != b){
              if(rank1[a] == rank1[b])
                  rank1[a]++;
              if(rank1[a] > rank1[b]){
                  parent1[b] = a;
              }
              else{
                  parent1[a] = b;
              }
          }
      }
  
      static void union_sets2(int a, int b) {
          a = find_set2(a);
          b = find_set2(b);
          if (a != b){
              if(rank2[a] == rank2[b])
                  rank2[a]++;
              if(rank2[a] > rank2[b]){
                  parent2[b] = a;
              }
              else{
                  parent2[a] = b;
              }
          }
      }
  
      static class Node{
          int a, b;
          Node(int x, int y){
              a = x;
              b = y;
          }
      }
  
      static AnotherReader sc;
      static PrintWriter out;
  
      public static void main(String[] args) throws Exception{
          if(memory)new Thread(null, new Runnable() {public void run(){try{new CF1559D().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 32).start();
          else new CF1559D().run();
      }
  
      void run()throws Exception
      {
          boolean oj = System.getProperty("ONLINE_JUDGE") != null;
          if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
          else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
          long s = System.currentTimeMillis();
          int t=1;
          //t=ni();
          //int k = t;
          while(t-->0) {/*p("Case #"+ (k-t) + ": ")*/;process();}
          out.flush();
          System.err.println(System.currentTimeMillis()-s+"ms");
          out.close();
      }
  
      static long power(long k, long c, long mod){
          long y = 1;
          while(c > 0){
              if(c%2 == 1)
                  y = y * k % mod;
              c = c/2;
              k = k * k % mod;
          }
          return y;
      }
  
      static int power(int x, int y, int p){ 
          int res = 1;
          x = x % p;
          while (y > 0) {
              if (y % 2 == 1)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
  
      static int log2(int N)
      {
          int result = (int)(Math.log(N) / Math.log(2));
          return result;
      }
  
   
      static void pn(Object o){out.println(o);}
      static void pn(int[] a){for(int i : a)out.print(i+" ");pn("");}
      static void pn(long[] a){for(long i : a)out.print(i+" ");pn("");}
      static void p(Object o){out.print(o);}
      static void YES(){out.println("YES");}
      static void NO(){out.println("NO");}
      static void yes(){out.println("yes");}
      static void no(){out.println("no");}
      static void p(int[] a){for(int i : a)out.print(i+" ");}
      static void p(long[] a){for(long i : a)out.print(i+" ");}
      static void pni(Object o){out.println(o);out.flush();}
      static int ni()throws IOException{return sc.nextInt();}
      static long nl()throws IOException{return sc.nextLong();}
      static double nd()throws IOException{return sc.nextDouble();}
      static String nln()throws IOException{return sc.nextLine();}
      static String ns()throws IOException{return sc.next();}
      static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
      static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
      static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
      static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
      static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
      
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
   
      static class AnotherReader{BufferedReader br; StringTokenizer st;
      AnotherReader()throws FileNotFoundException{
      br=new BufferedReader(new InputStreamReader(System.in));}
      AnotherReader(int a)throws FileNotFoundException{
      br = new BufferedReader(new FileReader("input.txt"));}
      String next()throws IOException{
      while (st == null || !st.hasMoreElements()) {try{
      st = new StringTokenizer(br.readLine());}
      catch (IOException  e){ e.printStackTrace(); }}
      return st.nextToken(); } int nextInt() throws IOException{
      return Integer.parseInt(next());}
      long nextLong() throws IOException
      {return Long.parseLong(next());}
      double nextDouble()throws IOException { return Double.parseDouble(next()); }
      String nextLine() throws IOException{ String str = ""; try{
      str = br.readLine();} catch (IOException e){
      e.printStackTrace();} return str;}}
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  }