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.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.Objects;
  import java.util.StringTokenizer;
  import java.io.Writer;
  import java.io.OutputStreamWriter;
  import java.io.BufferedReader;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   */
  public class Main {
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          OutputWriter out = new OutputWriter(outputStream);
          D1MochaAndDianaEasyVersion solver = new D1MochaAndDianaEasyVersion();
          solver.solve(1, in, out);
          out.close();
      }
  
      static class D1MochaAndDianaEasyVersion {
          public void solve(int testNumber, InputReader in, OutputWriter out) {
              int n = in.nextInt(), m1 = in.nextInt(), m2 = in.nextInt();
              UnionFind g1 = new UnionFind(n), g2 = new UnionFind(n);
              for (int i = 0; i < m1; i++) {
                  g1.unify(in.nextInt() - 1, in.nextInt() - 1);
              }
              for (int i = 0; i < m2; i++) {
                  g2.unify(in.nextInt() - 1, in.nextInt() - 1);
              }
              ArrayList<D1MochaAndDianaEasyVersion.Pair> list = new ArrayList<>();
              for (int i = 0; i < n; i++) {
                  for (int j = i + 1; j < n; j++) {
                      if (!g1.connected(i, j) && !g2.connected(i, j)) {
                          list.add(new D1MochaAndDianaEasyVersion.Pair(i + 1, j + 1));
                          g1.unify(i, j);
                          g2.unify(i, j);
                      }
                  }
              }
              out.println(list.size());
              for (D1MochaAndDianaEasyVersion.Pair p : list) out.println(p.a + " " + p.b);
          }
  
          static class Pair {
              int a;
              int b;
  
              Pair(int a, int b) {
                  this.a = a;
                  this.b = b;
              }
  
              public int hashCode() {
                  return Objects.hash(a, b);
              }
  
              public boolean equals(Object obj) {
                  D1MochaAndDianaEasyVersion.Pair that = (D1MochaAndDianaEasyVersion.Pair) obj;
                  return a == that.a && b == that.b;
              }
  
              public String toString() {
                  return "[" + a + ", " + b + "]";
              }
  
          }
  
          public class UnionFind {
              private int size;
              private int[] sz;
              private int[] id;
              private int numComponents;
  
              public UnionFind(int size) {
                  if (size <= 0) throw new IllegalArgumentException("Size <= 0 is not allowed");
                  this.size = numComponents = size;
                  sz = new int[size];
                  id = new int[size];
  
                  for (int i = 0; i < size; i++) {
                      id[i] = i;
                      sz[i] = 1;
                  }
              }
  
              public int find(int p) {
                  int root = p;
                  while (root != id[root]) root = id[root];
                  while (p != root) {
                      int next = id[p];
                      id[p] = root;
                      p = next;
                  }
                  return root;
              }
  
              public boolean connected(int p, int q) {
                  return find(p) == find(q);
              }
  
              public void unify(int p, int q) {
                  if (connected(p, q)) return;
                  int root1 = find(p);
                  int root2 = find(q);
  
                  if (sz[root1] < sz[root2]) {
                      sz[root2] += sz[root1];
                      id[root1] = root2;
                      sz[root1] = 0;
                  } else {
                      sz[root1] += sz[root2];
                      id[root2] = root1;
                      sz[root2] = 0;
                  }
                  numComponents--;
              }
  
          }
  
      }
  
      static class InputReader {
          BufferedReader reader;
          StringTokenizer tokenizer;
  
          public InputReader(InputStream stream) {
              reader = new BufferedReader(new InputStreamReader(stream), 32768);
              tokenizer = null;
          }
  
          public String next() {
              while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                  try {
                      tokenizer = new StringTokenizer(reader.readLine());
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              }
              return tokenizer.nextToken();
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
      }
  
      static class OutputWriter {
          private final PrintWriter writer;
  
          public OutputWriter(OutputStream outputStream) {
              writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
          }
  
          public OutputWriter(Writer writer) {
              this.writer = new PrintWriter(writer);
          }
  
          public void print(Object... objects) {
              for (int i = 0; i < objects.length; i++) {
                  if (i != 0) {
                      writer.print(' ');
                  }
                  writer.print(objects[i]);
              }
          }
  
          public void println(Object... objects) {
              print(objects);
              writer.println();
          }
  
          public void close() {
              writer.close();
          }
  
          public void println(int i) {
              writer.println(i);
          }
  
      }
  }
  
  