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.util.*;
  import java.io.*;
  public class Sol{
   
  /*   
  ->check n=1, int overflow , array bounds , all possibilites(dont stuck on 1 approach)
  ->Problem = Observation(constraints(m<=n/3 or k<=min(100,n)) 
             + Thinking + Technique (seg_tree,binary lift,rmq,bipart,dp,connected comp etc)
  ->solve or leave it (- tutorial improves you in minimal way -)
  */
   
  public static void main (String []args) {
  //precomp();
  
  int times=1;while(times-->0){solve();}out.close();}
  
  static ArrayList<Integer> adj1[],adj2[];
  static int v1[],v2[];
  
  static void solve() {  
   int n=ni();int m1=ni();int m2=ni();
   adj1=new ArrayList[n+1];
   adj2=new ArrayList[n+1];
   for(int i=0;i<=n;i++){adj1[i]=new ArrayList<Integer>();
                         adj2[i]=new ArrayList<Integer>();}
  
   for(int i=1;i<=m1;i++){int u=ni();int v=ni();adj1[u].add(v);adj1[v].add(u);}
   for(int i=1;i<=m2;i++){int u=ni();int v=ni();adj2[u].add(v);adj2[v].add(u);}
   
   v1=new int[n+1];
   v2=new int[n+1];
  
   int cv=1;
   int i=1;
   while(i<=n){
      if(v1[i]==0){dfs(i,0,adj1,v1,cv);cv++;}
      i++;
   }
   i=1;
   while(i<=n){
      if(v2[i]==0){dfs(i,0,adj2,v2,cv);cv++;}
      i++;
   }        
   ArrayList<Pair> al=new ArrayList<>();
   for (i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
          if(v1[i]==v1[j]){}
          else if(v2[i]==v2[j]){}
          else{
            al.add(new Pair(i,j));
            adj1[i].add(j);adj1[j].add(i);
            adj2[i].add(j);adj2[j].add(i);
            dfs(i,0,adj1,v1,cv);
            dfs(i,0,adj2,v2,cv);
            cv++;
         }
      }
   }
   out.println(al.size());
   for(Pair p:al){out.println(p.x+" "+p.y);}
  return;}
  
  static void dfs(int u,int p,ArrayList<Integer> adj[],int v[],int value){
      v[u]=value;
      for(int i:adj[u]){ if(i==p){continue;}dfs(i,u,adj,v,value);}    
   }
  
  static class Pair{int x,y;Pair(int x,int y){this.x=x;this.y=y;}}
  //-----------------Utility--------------------------------------------
  
  static long gcd(long a,long b){if(b==0)return a; return gcd(b,a%b);}
   
  static int Max=Integer.MAX_VALUE; static long mod=1000000007;
   
  static int v(char c){return (int)(c-'a');}
   
  public static long power(long x, long y )
      {
          //0^0 = 1
          long res = 1L;
          x = x%mod;
          while(y > 0)
          {
              if((y&1)==1)
                  res = (res*x)%mod;
              y >>= 1;
              x = (x*x)%mod;
          }
          return res;
      }
   
  /*static class Pair implements Comparable<Pair>{
          int id;int value;Pair next;
          public Pair(int id,int value) {
           
            this.id=id;this.value=value;next=null;
          }
          @Override
          public int compareTo(Pair p){return Long.compare(value,p.value);}
      }
  */
  
  //----------------------I/O---------------------------------------------
  
  static InputStream inputStream = System.in;
  static OutputStream outputStream = System.out;
  static FastReader in=new FastReader(inputStream);
  static PrintWriter out=new PrintWriter(outputStream);
   
  static class FastReader 
  { 
    BufferedReader br; 
    StringTokenizer st; 
   
          FastReader(InputStream is) {
              br = new BufferedReader(new InputStreamReader(is));
          }
   
    public String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
   
    public int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
   
    public long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
   
   public  double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
   
   
    String nextLine() 
    { 
        String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
  }
  static int ni() {
          try {
              boolean in = false;
              int res = 0;
              for (;;) {
                  int b = System.in.read() - '0';
                  if (b >= 0) {
                      in = true;
                      res = 10 * res + b;
                  }
                  else if (in)
                      return res;
              }
          } catch (IOException e) {
              throw new Error(e);
          }
      }
  static long nl(){return in.nextLong();}
  static double nd(){return in.nextDouble();}
  static String ns(){return in.nextLine();}
  }