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: //package codeforces.round738div2;
  
  import java.io.*;
  import java.util.*;
  
  import static java.lang.Math.*;
  
  //Think through the entire logic before jump into coding!
  //If you are out of ideas, take a guess! It is better than doing nothing!
  //Read both C and D, it is possible that D is easier than C for you!
  
  //Be aware of integer overflow!
  //If you find an answer and want to return immediately, don't forget to flush before return!
  
  public class D1 {
      static InputReader in;
      static PrintWriter out;
  
      public static void main(String[] args) {
          //initReaderPrinter(true);
          initReaderPrinter(false);
          //solve(in.nextInt());
          solve(1);
      }
  
      static void solve(int testCnt) {
          for (int testNumber = 0; testNumber < testCnt; testNumber++) {
              int n = in.nextInt(), m1 = in.nextInt(), m2 = in.nextInt();
              UnionFind uf1 = new UnionFind(n), uf2 = new UnionFind(n);
              for(int i = 0; i < m1; i++) {
                  int u = in.nextInt() - 1;
                  int v = in.nextInt() - 1;
                  uf1.union(u, v);
              }
              for(int i = 0; i < m2; i++) {
                  int u = in.nextInt() - 1;
                  int v = in.nextInt() - 1;
                  uf2.union(u, v);
              }
              List<Integer> l1 = new ArrayList<>(), l2 = new ArrayList<>();
              for(int x = 0; x < n - 1; x++) {
                  for(int y = x + 1; y < n; y++) {
                      if(!uf1.connected(x, y) && !uf2.connected(x, y)) {
                          l1.add(x + 1);
                          l2.add(y + 1);
                          uf1.union(x, y);
                          uf2.union(x, y);
                      }
                  }
              }
              out.println(l1.size());
              for(int i = 0; i < l1.size(); i++) {
                  out.println(l1.get(i) + " " + l2.get(i));
              }
          }
          out.close();
      }
  
      static class UnionFind {
          int[] root, sz;
          UnionFind(int n) {
              root = new int[n];
              sz = new int[n];
              for(int i = 0; i < n; i++) {
                  root[i] = i;
                  sz[i] = 1;
              }
          }
          boolean connected(int x, int y) {
              return findRoot(x) == findRoot(y);
          }
          int findRoot(int x) {
              if(root[x] != x) {
                  root[x] = findRoot(root[x]);
              }
              return root[x];
          }
          void union(int x, int y) {
              int rx = findRoot(x), ry = findRoot(y);
              if(rx != ry) {
                  if(sz[rx] >= sz[ry]) {
                      root[ry] = rx;
                      sz[rx] += sz[ry];
                  }
                  else {
                      root[rx] = ry;
                      sz[ry] += sz[rx];
                  }
              }
          }
      }
  
      static void initReaderPrinter(boolean test) {
          if (test) {
              try {
                  in = new InputReader(new FileInputStream("src/input.in"));
                  out = new PrintWriter(new FileOutputStream("src/output.out"));
              } catch (IOException e) {
                  e.printStackTrace();
              }
          } else {
              in = new InputReader(System.in);
              out = new PrintWriter(System.out);
          }
      }
  
      static class InputReader {
          BufferedReader br;
          StringTokenizer st;
  
          InputReader(InputStream stream) {
              try {
                  br = new BufferedReader(new InputStreamReader(stream), 32768);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
  
          String next() {
              while (st == null || !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());
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
  
          Integer[] nextIntArray(int n) {
              Integer[] a = new Integer[n];
              for (int i = 0; i < n; i++) a[i] = nextInt();
              return a;
          }
  
          int[] nextIntArrayPrimitive(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) a[i] = nextInt();
              return a;
          }
  
          int[] nextIntArrayPrimitiveOneIndexed(int n) {
              int[] a = new int[n + 1];
              for (int i = 1; i <= n; i++) a[i] = nextInt();
              return a;
          }
  
          Long[] nextLongArray(int n) {
              Long[] a = new Long[n];
              for (int i = 0; i < n; i++) a[i] = nextLong();
              return a;
          }
  
          long[] nextLongArrayPrimitive(int n) {
              long[] a = new long[n];
              for (int i = 0; i < n; i++) a[i] = nextLong();
              return a;
          }
  
          long[] nextLongArrayPrimitiveOneIndexed(int n) {
              long[] a = new long[n + 1];
              for (int i = 1; i <= n; i++) a[i] = nextLong();
              return a;
          }
  
          String[] nextStringArray(int n) {
              String[] g = new String[n];
              for (int i = 0; i < n; i++) g[i] = next();
              return g;
          }
      }
  }