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.*;
      import java.util.*;
      import java.util.InputMismatchException;
  
   public class Cf {
      class Union {
      int parent[];
      int rank[]; 
      public  int findParent(int node) {
          if(node==parent[node]) return node;
          return parent[node] = findParent(parent[node]);
      }
      public  void UnionByRank(int u,int v) {
          u = findParent(u);
          v = findParent(v);
          if(rank[u]<rank[v]) {
              parent[u] = v;
          }else if(rank[u]>rank[v]) {
              parent[v] = u;
          }else {
              parent[v] = u;
              rank[u]++;
          }
      }
      public  void init(int n) {
          parent = new int[n+1];
          rank = new int[n+1];
          for(int i=1;i<=n;i++) {
              parent[i] = i;
              rank[i] = 0;
          }
      }
  }
       int mod = (int)1e9+7;
      public static void main(String[] args) throws Exception {
          Cf cf = new Cf();
          cf.solve();
      }
      public void solve() {
          InputReader in = new InputReader(System.in);
          OutputWriter out = new OutputWriter(System.out);
          Union un1 = new Union();
          Union un2 = new Union();
          int n = in.readInt();
          int m1 = in.readInt();
          int m2 = in.readInt();
          un1.init(n);
          un2.init(n);
          for(int i=0;i<m1;i++) {
              int a = in.readInt();
              int b = in.readInt();
              un1.UnionByRank(a,b);
          }
          for(int i=0;i<m2;i++) {
              int a = in.readInt();
              int b = in.readInt();
              un2.UnionByRank(a,b);
          }
          List<Integer[]> adj = new ArrayList<>();
          for(int i=1;i<n;i++) {
              for(int j=i+1;j<=n;j++) {
                  int a = un1.findParent(i);
                  int b = un1.findParent(j);
                  if(a==b) {
                      continue;
                  }
                  int c = un2.findParent(i);
                  int d = un2.findParent(j);
                  if(c==d) {
                      continue;
                  }
                  un1.UnionByRank(a,b);
                  un2.UnionByRank(c,d);
                  adj.add(new Integer[]{i,j});
              }
          }
          if(adj.size()==0) {
              out.printLine(0);
          }else {
              out.printLine(adj.size());
              for(int i=0;i<adj.size();i++) {
                  Integer[] vv = adj.get(i);
                  out.printLine(vv[0]+" "+vv[1]);
              }
          }
  
         
          
                      
      }
      //logn time
      public long findPower(long x,long n) {
          long ans = 1;
          long nn = n;
          while(nn>0) {
              if(nn%2==1) {
                  ans = (ans*x) % mod;
                  nn-=1;
              }else {
                  x = (x*x)%mod;
                  nn/=2;
              }
          }
          return ans%mod;
      }
       
          //FAST IO
          private static class InputReader {
              private InputStream stream;
              private byte[] buf = new byte[1024];
              private int curChar;
              private int numChars;
              private SpaceCharFilter filter;
       
              public InputReader(InputStream stream) {
                  this.stream = stream;
              }
       
              public int read() {
                  if (numChars == -1) {
                      throw new InputMismatchException();
                  }
                  if (curChar >= numChars) {
                      curChar = 0;
                      try {
                          numChars = stream.read(buf);
                      } catch (IOException e) {
                          throw new InputMismatchException();
                      }
                      if (numChars <= 0) {
                          return -1;
                      }
                  }
                  return buf[curChar++];
              }
       
              public int readInt() {
                  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;
              }
       
              public String readString() {
                  int c = read();
                  while (isSpaceChar(c)) {
                      c = read();
                  }
                  StringBuilder res = new StringBuilder();
                  do {
                      res.appendCodePoint(c);
                      c = read();
                  } while (!isSpaceChar(c));
                  return res.toString();
              }
       
              public double readDouble() {
                  int c = read();
                  while (isSpaceChar(c)) {
                      c = read();
                  }
                  int sgn = 1;
                  if (c == '-') {
                      sgn = -1;
                      c = read();
                  }
                  double res = 0;
                  while (!isSpaceChar(c) && c != '.') {
                      if (c == 'e' || c == 'E') {
                          return res * Math.pow(10, readInt());
                      }
                      if (c < '0' || c > '9') {
                          throw new InputMismatchException();
                      }
                      res *= 10;
                      res += c - '0';
                      c = read();
                  }
                  if (c == '.') {
                      c = read();
                      double m = 1;
                      while (!isSpaceChar(c)) {
                          if (c == 'e' || c == 'E') {
                              return res * Math.pow(10, readInt());
                          }
                          if (c < '0' || c > '9') {
                              throw new InputMismatchException();
                          }
                          m /= 10;
                          res += (c - '0') * m;
                          c = read();
                      }
                  }
                  return res * sgn;
              }
       
              public long readLong() {
                  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;
              }
       
              public boolean isSpaceChar(int c) {
                  if (filter != null) {
                      return filter.isSpaceChar(c);
                  }
                  return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
              }
       
              public String next() {
                  return readString();
              }
       
              public interface SpaceCharFilter {
                  public boolean isSpaceChar(int ch);
              }
          }
       
          private 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]);
                  }
                  writer.flush();
              }
       
              public void printLine(Object... objects) {
                  print(objects);
                  writer.println();
                  writer.flush();
              }
       
              public void close() {
                  writer.close();
              }
       
              public void flush() {
                  writer.flush();
              }
          }
      }