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.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.util.*;
  
  /**
   * 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);
          PrintWriter out = new PrintWriter(outputStream);
          Solution solver = new Solution();
          boolean multipleTC = false;
          int testCount = multipleTC ? Integer.parseInt(in.next()) : 1;
          for (int i = 1; i <= testCount; i++)
              solver.solve(in, out, i);
          out.close();
  
      }
      static class Solution {
          PrintWriter out;
          InputReader in;
  
          public void solve(InputReader in, PrintWriter out, int test) {
              this.out = out;
              this.in = in;
              int n = ni(), m1 = ni(), m2 = ni();
              DSU ob1 = new DSU(n);
              DSU ob2 = new DSU(n);
              for(int i = 0; i < m1; i++)
                  ob1.unite(ni() - 1, ni() - 1);
              for(int i = 0; i < m2; i++)
                  ob2.unite(ni() - 1, ni() - 1);
              int cnt = 0;
              ArrayList<int[]> ans = new ArrayList<>();
              for(int i = 0; i < n; i++) {
                  for(int j = 0; j < n; j++){
                      if(ob1.find(i) != ob1.find(j) && ob2.find(i) != ob2.find(j)) {
                          cnt++;
                          ob1.unite(i, j);
                          ob2.unite(i, j);
                          ans.add(new int[]{i + 1, j + 1});
                      }
                  }
              }
              pn(cnt);
              for(int[] hola: ans)
                  pn(hola[0] + " " + hola[1]);
          }
  
          class DSU{
              int[] par, sz;
              long ans = 0;
              DSU(int n){
                  par = new int[n];
                  sz = new int[n];
                  int i = 0;
                  for(i = 0; i < n; i++){
                      par[i] = i;
                      sz[i] = 1;
                  }
              }
              int find(int x){
                  if(par[x] != x)
                      return par[x] = find(par[x]);
                  return par[x];
              }
              void unite(int x, int y){
                  int x_root = find(x);
                  int y_root = find(y);
                  if(x_root == y_root)
                      return;
                  if(sz[x_root] <= sz[y_root]){
                      par[x_root] = y_root;
                      sz[y_root] += sz[x_root];
                  }
                  else{
                      par[y_root] = x_root;
                      sz[x_root] += sz[y_root];
                  }
              }
          }
  
          final Comparator<Tuple> com = new Comparator<Tuple>() {
              public int compare(Tuple x, Tuple y) {
                  int xx = Integer.compare(x.x, y.x);
                  if (xx == 0) {
                      if(x.y != y.y)
                          return Integer.compare(x.y, y.y);
                      else return Integer.compare(x.z, x.z);
                  } else {
                      return xx;
                  }
              }
          };
  
  
          int gcd(int a, int b)
          {
              if (a == 0)
                  return b;
  
              return gcd(b%a, a);
          }
  
  
          String n(){
              return in.next();
          }
  
          int ni() {
              return in.nextInt();
          }
  
          long nl() {
              return in.nextLong();
          }
  
          void pn(long zx) {
              out.println(zx);
          }
  
          void pn(String sz) {
              out.println(sz);
          }
  
          void pn(double dx){
              out.println(dx);
          }
  
          class Tuple {
              int x;
              int y;
              int z;
              Tuple(int a, int b, int c) {
                  x = a;
                  y = b;
                  z = c;
              }
          }
  
      }
  
      static class InputReader {
          private InputStream stream;
          private byte[] buf = new byte[1024];
          private int curChar;
          private int numChars;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          public int read() {
              if (numChars == -1) {
                  throw new UnknownError();
              }
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new UnknownError();
                  }
                  if (numChars <= 0) {
                      return -1;
                  }
              }
              return buf[curChar++];
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
          public long nextLong() {
              return Long.parseLong(next());
          }
  
          public String next() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              StringBuffer res = new StringBuffer();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
  
              return res.toString();
          }
  
          private boolean isSpaceChar(int c) {
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
      }
  }