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 javax.print.attribute.IntegerSyntax;
  import java.io.*;
  import java.util.*;
  
  /**
   * A simple template for competitive programming problems.
   */
  public class Solution {
      //InputReader in = new InputReader("input.txt");
      final InputReader in = new InputReader(System.in);
  
      final PrintWriter out = new PrintWriter(System.out);
  
      void solve() {
          int n = in.nextInt(); int m1 = in.nextInt(); int m2 = in.nextInt();
          UnionFind u1 = new UnionFind(n+1);
          UnionFind u2 = new UnionFind(n+1);
  
          for(int i=0; i<m1; i++) {
              int u = in.nextInt(); int v = in.nextInt();
              u1.union(u, v);
          }
  
          for(int i=0; i<m2; i++) {
              int u = in.nextInt(); int v = in.nextInt();
              u2.union(u, v);
          }
  
          List<Integer> f = new ArrayList<>();
          List<Integer> s = new ArrayList<>();
  
          for(int i=1; i<=n; i++) {
              for(int j=i+1; j<=n; j++) {
                  if(!u1.connected(i, j) && !u2.connected(i,j)) {
                      f.add(i);
                      s.add(j);
                      u1.union(i, j);
                      u2.union(i, j);
                  }
              }
          }
  
          out.println(f.size());
          for(int i=0; i<f.size(); i++) {
              out.println(f.get(i) + " " + s.get(i));
          }
      }
  
      public class UnionFind {
          private final int[] component;
          private final int[] size;
          private int componentCount;
  
          /**
           * Initially each object is only connected to itself.
           */
          public UnionFind(int numObjects) {
              component = new int[numObjects];
              size = new int[numObjects];
              componentCount = numObjects;
              for (int i = 0; i < numObjects; i++) {
                  component[i] = i;
                  size[i] = 1;
              }
          }
  
          /**
           * Returns the component ID of the object.
           */
          public int find(int p) {
              if (p < 0 || p >= component.length) throw new IllegalArgumentException("Illegal object ID.");
              int root = p;
              while (component[root] != root)
                  root = component[root];
              while (root != component[p]) {
                  int next = component[p];
                  component[p] = root;
                  p = next;
              }
              return root;
          }
  
          /**
           * Merges the components of the objects.
           */
          public void union(int p, int q) {
              if (p < 0 || p >= component.length) throw new IllegalArgumentException("Illegal object ID.");
              if (q < 0 || q >= component.length) throw new IllegalArgumentException("Illegal object ID.");
              p = find(p);
              q = find(q);
              if (p == q) return;
              componentCount--;
              if (size[p] < size[q]) {
                  component[p] = q;
                  size[q] += size[p];
              } else {
                  component[q] = p;
                  size[p] += size[q];
              }
          }
  
          /**
           * Returns true if the objects are in the same component, false otherwise.
           */
          public boolean connected(int p, int q) {
              return find(p) == find(q);
          }
  
          /**
           * Returns the size of the component p belong to.
           */
          public int componentSize(int p) {
              return size[find(p)];
          }
  
          /**
           * Returns the number of components.
           */
          public int count() {
              return componentCount;
          }
      }
  
      private void shuffle(int[] a) {
          int n = a.length;
          Random random = new Random();
          random.nextInt();
          for (int i = 0; i < n; i++) {
              int change = i + random.nextInt(n - i);
              swap(a, i, change);
          }
      }
  
      private static void swap(int[] a, int i, int j) {
          int helper = a[i];
          a[i] = a[j];
          a[j] = helper;
      }
  
      public static void main(final String[] args) throws FileNotFoundException {
          final Solution s = new Solution();
          final Long t1 = System.currentTimeMillis();
          s.solve();
          System.err.println(System.currentTimeMillis() - t1 + " ms");
          s.out.close();
      }
  
      public Solution() throws FileNotFoundException {
      }
  
      private static class InputReader {
          private final InputStream stream;
          private final byte[] buf = new byte[1024];
          private int curChar;
          private int numChars;
          Random r = new Random();
          InputReader(final InputStream stream) {
              this.stream = stream;
          }
  
          InputReader(final String fileName) {
              InputStream stream = null;
              try {
                  stream = new FileInputStream(fileName);
              } catch (final FileNotFoundException e) {
                  e.printStackTrace();
              }
              this.stream = stream;
          }
  
          int[] nextArray(final int n) {
              final int[] arr = new int[n];
              for (int i = 0; i < n; i++)
                  arr[i] = nextInt();
              return arr;
          }
  
          int[][] nextMatrix(final int n, final int m) {
              final int[][] matrix = new int[n][m];
              for (int i = 0; i < n; i++)
                  for (int j = 0; j < m; j++)
                      matrix[i][j] = nextInt();
              return matrix;
          }
  
          String nextLine() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              final StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isEndOfLine(c));
              return res.toString();
          }
  
          String nextString() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              final StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          long nextLong() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              long res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          int nextInt() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          double nextDouble() {
              return Double.parseDouble(nextString());
          }
  
          private int read() {
              if (numChars == -1)
                  throw new InputMismatchException();
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (final IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0)
                      return -1;
              }
              return buf[curChar++];
          }
  
          private boolean isSpaceChar(final int c) {
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          private boolean isEndOfLine(final int c) {
              return c == '\n' || c == '\r' || c == -1;
          }
      }
  
  }