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.lang.reflect.Array;
  import java.math.BigInteger;
  import java.util.*;
  import java.util.BitSet;
  import java.util.function.BinaryOperator;
  
  public class D {
      static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              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;
          }
      }
  
      static FastReader s = new FastReader();
      static PrintWriter out = new PrintWriter(System.out);
  
      private static int[] rai(int n) {
          int[] arr = new int[n];
          for (int i = 0; i < n; i++) {
              arr[i] = s.nextInt();
          }
          return arr;
      }
  
      private static int[][] rai(int n, int m) {
          int[][] arr = new int[n][m];
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  arr[i][j] = s.nextInt();
              }
          }
          return arr;
      }
  
      private static long[] ral(int n) {
          long[] arr = new long[n];
          for (int i = 0; i < n; i++) {
              arr[i] = s.nextLong();
          }
          return arr;
      }
  
      private static long[][] ral(int n, int m) {
          long[][] arr = new long[n][m];
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  arr[i][j] = s.nextLong();
              }
          }
          return arr;
      }
  
      private static int ri() {
          return s.nextInt();
      }
  
      private static long rl() {
          return s.nextLong();
      }
  
      private static String rs() {
          return s.next();
      }
  
  
      static long gcd(long a,long b)
      {
          if(b==0)
          {
              return a;
          }
          return gcd(b,a%b);
      }
  
      static int MOD=(int)1e9+7;
  
      public static int primeFactors(long n)
      {
          // Print the number of 2s that divide n
          int count=0;
          while (n % 2 == 0) {
              count++;
              n /= 2;
          }
  
          // n must be odd at this point.  So we can
          // skip one element (Note i = i +2)
          for (long i = 3; i * i<=n; i += 2) {
              // While i divides n, print i and divide n
              while (n % i == 0) {
                  count++;
                  n /= i;
              }
          }
  
          // This condition is to handle the case whien
          // n is a prime number greater than 2
          if (n > 2)
              count++;
  
          return count;
      }
  
      static void dfs(List<Integer>[] arr, int node, int ind, boolean[] vis, int[] map)
      {
          vis[node] = true;
          map[node] = ind;
  
          for(int i:arr[node])
          {
              if(!vis[i])
              {
                  dfs(arr,i,ind,vis,map);
              }
          }
      }
      public static void main(String[] args) {
          StringBuilder ans = new StringBuilder();
  
  //        int t = ri();
          int t=1;
          while(t-- >0)
          {
              int n=ri();
              int m1 = ri();
              int m2 = ri();
  
              List<Integer>[] arr1 = new ArrayList[n];
              List<Integer>[] arr2 = new ArrayList[n];
  
              for(int i=0;i<n;i++)
              {
                  arr1[i] = new ArrayList<>();
                  arr2[i] = new ArrayList<>();
  
              }
  
              for(int i=0;i<m1;i++)
              {
                  int a=ri()-1;
                  int b=ri()-1;
  
                  arr1[a].add(b);
                  arr1[b].add(a);
              }
  
              for(int i=0;i<m2;i++)
              {
                  int a=ri()-1;
                  int b=ri()-1;
  
                  arr2[a].add(b);
                  arr2[b].add(a);
              }
  
              int[] map1 = new int[n];
              int[] map2 = new int[n];
  
              boolean[] vis = new boolean[n];
              int ind = 0;
              for(int i=0;i<n;i++)
              {
                  if(!vis[i])
                  {
                      dfs(arr1,i,ind, vis, map1);
                      ind++;
                  }
              }
  
              vis = new boolean[n];
              ind = 0;
  
              for(int i=0;i<n;i++)
              {
                  if(!vis[i])
                  {
                      dfs(arr2,i,ind,vis,map2);
                      ind++;
                  }
              }
  
  //            HashSet<Node> set1 = new HashSet<>();
  //            HashSet<Node> set2 = new HashSet<>();
  //            boolean[] v1 = new boolean[n];
  //            boolean[] v2 = new boolean[n];
              int val = n-Math.max(m1,m2)-1;
              ans.append(val).append("\n");
              int count = 0;
              for(int i=0;i<n;i++)
              {
  //                if(v1[map1[i]] || v2[map2[i]])
  //                {
  //                    continue;
  //                }
                  HashSet<Integer> set1 = new HashSet<>();
                  HashSet<Integer> set2 = new HashSet<>();
                  for(int j=i+1;j<n;j++)
                  {
  
  //                    Node n1 = new Node(map1[i],map1[j]);
  //                    Node n2 = new Node(map2[i],map2[j]);
  //                    Node n3 = new Node(map1[j],map1[i]);
  //                    Node n4 = new Node(map2[j],map2[i]);
  //                    && !set1.contains(n1) && !set2.contains(n2)&& !set1.contains(n3) && !set2.contains(n4)
                      if(map1[i]!=map1[j] && map2[i]!=map2[j] && !set1.contains(map1[j]) && !set2.contains(map2[j]))
                      {
                          ans.append(i+1).append(" ").append(j+1).append("\n");
  
                          set1.add(map1[j]);
                          set2.add(map2[j]);
  
  //                        set1.add(n1);
  //                        set2.add(n2);
  //                        set1.add(n3);
  //                        set2.add(n4);
                          count++;
                      }
  //                    if(count==val)
  //                    {
  //                        break;
  //                    }
                  }
                  for(int j=0;j<n;j++)
                  {
                      if(set1.contains(map1[j]))
                      {
                          map1[j]=map1[i];
                      }
                      if(set2.contains(map2[j]))
                      {
                          map2[j]=map2[i];
                      }
                  }
  //                v1[map1[i]]=true;
  //                v2[map2[i]] = true;
  //                System.out.println(Arrays.toString(map1));
  //                System.out.println(Arrays.toString(map2));
  //                if(count==val)
  //                {
  //                    break;
  //                }
              }
  //            System.out.println(set1);
  //            System.out.println(set2);
          }
          out.print(ans.toString());
          out.flush();
      }
  
      static class Node
      {
          int v1,v2;
  
          public Node(int v1, int v2) {
              this.v1 = v1;
              this.v2 = v2;
          }
  
          @Override
          public boolean equals(Object o) {
              if (this == o) return true;
              if (o == null || getClass() != o.getClass()) return false;
              Node node = (Node) o;
              return v1 == node.v1 && v2 == node.v2;
          }
  
          @Override
          public int hashCode() {
              return Objects.hash(v1, v2);
          }
  
          @Override
          public String toString() {
              return "Node{" +
                      "v1=" + v1 +
                      ", v2=" + v2 +
                      '}';
          }
      }
  
  }