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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.Arrays;
  import java.util.Random;
  import java.util.StringTokenizer;
  
  public final class D {
  
      private static final class UnionFind {
          private final int[] parent;
          private final int[] size;
          private int count;
  
          private UnionFind(int n) {
              parent = new int[n];
              size = new int[n];
              count = n;
              for (int i = 0; i < n; i++) {
                  parent[i] = i;
                  size[i] = 1;
              }
          }
  
          public int find(int p) {
              // path compression
              while (p != parent[p]) {
                  parent[p] = parent[parent[p]];
                  p = parent[p];
              }
              return p;
          }
  
          public void union(int p, int q) {
              final int rootP = find(p);
              final int rootQ = find(q);
              if (rootP == rootQ) {
                  return;
              }
              // union by size
              if (size[rootP] > size[rootQ]) {
                  parent[rootQ] = rootP;
                  size[rootP] += size[rootQ];
                  size[rootQ] = 0;
              } else {
                  parent[rootP] = rootQ;
                  size[rootQ] += size[rootP];
                  size[rootP] = 0;
              }
              count--;
          }
  
          public int count() { return count; }
  
          public int[] size() { return size; }
      }
  
      public static void main(String[] args) {
          final FastScanner fs = new FastScanner();
          final int n = fs.nextInt();
          UnionFind uf1 = new UnionFind(n);
          UnionFind uf2 = new UnionFind(n);
          int m1 = fs.nextInt();
          int m2 = fs.nextInt();
          for (int i = 0; i < m1; i++) {
              int u = fs.nextInt() - 1;
              int v = fs.nextInt() - 1;
              uf1.union(u, v);
          }
          for (int i = 0; i < m2; i++) {
              int u = fs.nextInt() - 1;
              int v = fs.nextInt() - 1;
              uf2.union(u, v);
          }
  
          int count = 0;
          StringBuilder sb = new StringBuilder();
          for (int i = 0; i < n; i++) {
              for (int j = i + 1; j < n; j++) {
                  if (uf1.find(i) != uf1.find(j) && uf2.find(i) != uf2.find(j)) {
                      count++;
                      sb.append(i + 1).append(' ').append(j + 1).append('\n');
                      uf1.union(i, j);
                      uf2.union(i, j);
                  }
              }
          }
          System.out.println(count);
          System.out.println(sb);
      }
  
      static final class Utils {
          private static class Shuffler {
              private static void shuffle(int[] x) {
                  final Random r = new Random();
  
                  for (int i = 0; i <= x.length - 2; i++) {
                      final int j = i + r.nextInt(x.length - i);
                      swap(x, i, j);
                  }
              }
  
              private static void shuffle(long[] x) {
                  final Random r = new Random();
  
                  for (int i = 0; i <= x.length - 2; i++) {
                      final int j = i + r.nextInt(x.length - i);
                      swap(x, i, j);
                  }
              }
  
              private static void swap(int[] x, int i, int j) {
                  final int t = x[i];
                  x[i] = x[j];
                  x[j] = t;
              }
  
              private static void swap(long[] x, int i, int j) {
                  final long t = x[i];
                  x[i] = x[j];
                  x[j] = t;
              }
          }
  
          public static void shuffleSort(int[] arr) {
              Shuffler.shuffle(arr);
              Arrays.sort(arr);
          }
  
          public static void shuffleSort(long[] arr) {
              Shuffler.shuffle(arr);
              Arrays.sort(arr);
          }
  
          private Utils() {}
      }
  
      static class FastScanner {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st = new StringTokenizer("");
  
          private String next() {
              while (!st.hasMoreTokens()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      //noinspection CallToPrintStackTrace
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          int[] nextIntArray(int n) {
              final int[] a = new int[n];
              for (int i = 0; i < n; i++) { a[i] = nextInt(); }
              return a;
          }
  
          long[] nextLongArray(int n) {
              final long[] a = new long[n];
              for (int i = 0; i < n; i++) { a[i] = nextLong(); }
              return a;
          }
      }
  }
  