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: //Some of the methods are copied from GeeksforGeeks Website  
  import java.util.*;
  import java.lang.*;
  import java.io.*;
  public class Main
  { 
    //static Scanner sc=new Scanner(System.in)
    static  Reader sc=new Reader();
    // static FastReader sc=new FastReader(System.in);
    
    static long mod = (long)(1e9)+ 7;
    static int max_num=(int)1e3+5;
    static int parent1[]=new int[max_num];
    static int size1[]=new int[max_num];
    
    static int parent2[]=new int[max_num];
    static int size2[]=new int[max_num];
    
    static void make1(int v)
     {
        parent1[v]=v;
        size1[v]=1;
     }
   static int find1(int v) 
    {
       if(v==parent1[v]) return v;
       return parent1[v]=find1(parent1[v]);
    }
   static void union1(int a,int b)
    {
       int x=find1(a);
       int y=find1(b);
       if(x!=y)
        {
           if(size1[x]<size1[y])
             {
                x=x+y;
                y=x-y;
                x=x-y;
             }
           parent1[y]=x;
           size1[x]+=size1[y];
        }
    }
    
     static void make2(int v)
     {
        parent2[v]=v;
        size2[v]=1;
     }
   static int find2(int v) 
    {
       if(v==parent2[v]) return v;
       return parent2[v]=find2(parent2[v]);
    }
   static void union2(int a,int b)
    {
       int x=find2(a);
       int y=find2(b);
       if(x!=y)
        {
           if(size2[x]<size2[y])
             {
                x=x+y;
                y=x-y;
                x=x-y;
             }
           parent2[y]=x;
           size2[x]+=size2[y];
        }
    }
   public static void main (String[] args) throws java.lang.Exception
     {
  	try{
  	    /*
  	        int n=sc.nextInt();
  	        Collections.sort(al,Collections.reverseOrder());
  	     
  	        long n=sc.nextLong();
  	        String s=sc.next();
  	        StringBuilder sb=new StringBuilder();
  	     */
  		  int t =1;// sc.nextInt();
  		  while(t-->0)
  		    { 
  		       int n=sc.nextInt();
  		       int m1=sc.nextInt();
  		       int m2=sc.nextInt();
  		       
  		       for(int i=0;i<=n;i++)
  		         {
  		            make1(i);
  		            make2(i);
  		         }
  		      
  		      for(int i=0;i<m1;i++)
  		        {
  		           int u=sc.nextInt();
  		           int v=sc.nextInt();
  		           
  		           union1(u,v);
  		        }
  		        
  		       for(int i=0;i<m2;i++)
  		        {
  		           int u=sc.nextInt();
  		           int v=sc.nextInt();
  		           
  		           union2(u,v);
  		        }
  		      Set<String> set=new HashSet<>();
  		      ArrayList<Integer> al1=new ArrayList<>();
  		      ArrayList<Integer> al2=new ArrayList<>();
  		      for(int i=1;i<=n;i++)
  		        {
  		           for(int j=1;j<=n;j++)
  		             {
  		                if(i==j) continue;
  		                String key=i+" "+j;
  		                if(set.contains(key))
  		                 continue;
  		               
  		                int x=find1(i);
  		                int y=find1(j);
  		                
  		                int xx=find2(i);
  		                int yy=find2(j);
  		               
  		                if(x!=y && xx!=yy)
  		                  {
  		                     al1.add(i);
  		                     al2.add(j);
  		                     union1(i,j);
  		                     union2(i,j);
  		                     set.add(key);
  		                  }
  		                
  		             }
  		        }
  		       
  		      out.println(al1.size());
  		      for(int i=0;i<al1.size();i++)
  		       out.println(al1.get(i)+" "+al2.get(i));
  		    }
  	     out.flush();
  	     out.close();
  	   }     
  	catch(Exception e)
  		 {}
  	}
   
   /*
     ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE...
   */
   
  static void flag(boolean flag)
     {
         out.println(flag ? "YES" : "NO");
         out.flush();
     }
     
   /*                     
      Map<Long,Long> map=new HashMap<>();
               for(int i=0;i<n;i++)
                 {
                    if(!map.containsKey(a[i]))
                     map.put(a[i],1);
                   else
                     map.replace(a[i],map.get(a[i])+1);
                 }
       
      Set<Map.Entry<Long,Long>> hmap=map.entrySet();
               for(Map.Entry<Long,Long> data : hmap)
                 {
            
                 }
         
     */
     
  //  static class Pair
  //    {
  //       int x,y;
  //       Pair(int x,int y)
  //        {
  //           this.x=x;
  //           this.y=y;
  //        }
  //    }
  
  //  Arrays.sort(p, new Comparator<Pair>()
  //     {
  //        @Override
  //        public int compare(Pair o1,Pair o2)
  //        {
  //           if(o1.x>o2.x) return 1;
  //           else if(o1.x==o2.x)
  //             {
  //                if(o1.y>o2.y) return 1;
  //                else return -1;
  //              }
  //           else return -1;
  //       }});
  
  static void print(int a[])
    {
       int n=a.length;
       for(int i=0;i<n;i++)
         {
            out.print(a[i]+" ");
         }
       out.println();
       out.flush();
    }
  static void print(long a[])
    {
       int n=a.length;
       for(int i=0;i<n;i++)
         {
            out.print(a[i]+" ");
         }
       out.println();
       out.flush();
    } 
  static void print_int(ArrayList<Integer> al)
    {
       int si=al.size();
       for(int i=0;i<si;i++)
         {
            out.print(al.get(i)+" ");
         }
       out.println();
       out.flush();
    }
  static void print_long(ArrayList<Long> al)
    {
       int si=al.size();
       for(int i=0;i<si;i++)
         {
            out.print(al.get(i)+" ");
         }
       out.println();
       out.flush();
    }
    
  static int LowerBound(int a[], int x) 
   { // x is the target value or key
    int l=-1,r=a.length;
    while(l+1<r) {
      int m=(l+r)>>>1;
      if(a[m]>=x) r=m;
      else l=m;
    }
    return r;
  }
  
   static int UpperBound(int a[], int x)
    {// x is the key or target value
      int l=-1,r=a.length;
      while(l+1<r) {
         int m=(l+r)>>>1;
         if(a[m]<=x) l=m;
         else r=m;
      }
      return l+1;
   }
  static void DFS(ArrayList<Integer> graph[],boolean[] visited, int u)
  	{
          visited[u]=true;
          int v=0;
          for(int i=0;i<graph[u].size();i++)
          {
              v=graph[u].get(i);
              if(!visited[v])
                 DFS(graph,visited,v);
          }
    } 
  static boolean[] prime(int num)
   {
  	      boolean[] bool = new boolean[num];
  		     
  		      for (int i = 0; i< bool.length; i++) {
  		         bool[i] = true;
  		      }
  		      for (int i = 2; i< Math.sqrt(num); i++) {
  		         if(bool[i] == true) {
  		            for(int j = (i*i); j<num; j = j+i) {
  		               bool[j] = false;
  		            }
  		         }
  		      }
  		      if(num >= 0) {
  		    	  bool[0] = false;
  		    	  bool[1] = false;
  		      }
  		      
  		      return bool;
    }
  static long nCr(long a,long b,long mod)
  {
   return (((fact[(int)a] * modInverse(fact[(int)b],mod))%mod * modInverse(fact[(int)(a - b)],mod))%mod + mod)%mod;
  }
  static long fact[]=new long[max_num];
  static void fact_fill()
   {
     long fact[]=new long[max_num];
     fact[0]=1l;
  	for(int i=1;i<max_num;i++)
  	  {
  	    fact[i]=(fact[i-1]*(long)i);
  	    if(fact[i]>=mod)
  	      fact[i]%=mod;
  	  } 
   }
  static long modInverse(long a, long m)
  	    {
  	       return power(a, m - 2, m);
  	    }
  static long power(long x, long y, long m)
  	    {
  	        if (y == 0)
  	            return 1;
  	        long p = power(x, y / 2, m) % m;
  	        p = (long)((p * (long)p) % m);
  	        if (y % 2 == 0)
  	            return p;
  	        else
  	            return (long)((x * (long)p) % m);
  	    }
  static long sum_array(int a[])
   {
      int n=a.length;
      long sum=0;
      for(int i=0;i<n;i++)
       sum+=a[i];
      return sum;
   }
  static long sum_array(long a[])
   {
      int n=a.length;
      long sum=0;
      for(int i=0;i<n;i++)
       sum+=a[i];
      return sum;
   }
  
  static void sort(int[] a) 
     {
  		ArrayList<Integer> l=new ArrayList<>();
  		for (int i:a) l.add(i);
  		Collections.sort(l);
  		for (int i=0; i<a.length; i++) a[i]=l.get(i);
  	}
  static void sort(long[] a) 
     {
  		ArrayList<Long> l=new ArrayList<>();
  		for (long i:a) l.add(i);
  		Collections.sort(l);
  		for (int i=0; i<a.length; i++) a[i]=l.get(i);
  	}
  
  static void reverse_array(int a[])
   {
      int n=a.length;
      int i,t; 
      for (i = 0; i < n / 2; i++) { 
              t = a[i]; 
              a[i] = a[n - i - 1]; 
              a[n - i - 1] = t; 
          } 
   }
  static void reverse_array(long a[])
   {
      int n=a.length;
      int i; long t; 
      for (i = 0; i < n / 2; i++) { 
              t = a[i]; 
              a[i] = a[n - i - 1]; 
              a[n - i - 1] = t; 
          } 
   }
  
  static long gcd(long a, long b) 
      { 
          if (a == 0) 
              return b; 
            
          return gcd(b%a, a); 
      } 
  static int gcd(int a, int b) 
      { 
          if (a == 0) 
              return b; 
            
          return gcd(b%a, a); 
      } 
  
     static class FastReader{
   
          byte[] buf = new byte[2048];
          int index, total;
          InputStream in;
   
          FastReader(InputStream is) {
              in = is;
          }
   
          int scan() throws IOException {
              if (index >= total) {
                  index = 0;
                  total = in.read(buf);
                  if (total <= 0) {
                      return -1;
                  }
              }
              return buf[index++];
          }
   
          String next() throws IOException {
              int c;
              for (c = scan(); c <= 32; c = scan());
              StringBuilder sb = new StringBuilder();
              for (; c > 32; c = scan()) {
                  sb.append((char) c);
              }
              return sb.toString();
          }
   
          int nextInt() throws IOException {
              int c, val = 0;
              for (c = scan(); c <= 32; c = scan());
              boolean neg = c == '-';
              if (c == '-' || c == '+') {
                  c = scan();
              }
              for (; c >= '0' && c <= '9'; c = scan()) {
                  val = (val << 3) + (val << 1) + (c & 15);
              }
              return neg ? -val : val;
          }
   
          long nextLong() throws IOException {
              int c;
              long val = 0;
              for (c = scan(); c <= 32; c = scan());
              boolean neg = c == '-';
              if (c == '-' || c == '+') {
                  c = scan();
              }
              for (; c >= '0' && c <= '9'; c = scan()) {
                  val = (val << 3) + (val << 1) + (c & 15);
              }
              return neg ? -val : val;
          }
      }
     
      static class Reader 
      { 
          final private int BUFFER_SIZE = 1 << 16; 
          private DataInputStream din; 
          private byte[] buffer; 
          private int bufferPointer, bytesRead; 
    
          public Reader() 
          { 
              din = new DataInputStream(System.in); 
              buffer = new byte[BUFFER_SIZE]; 
              bufferPointer = bytesRead = 0; 
          } 
    
          public Reader(String file_name) throws IOException 
          { 
              din = new DataInputStream(new FileInputStream(file_name)); 
              buffer = new byte[BUFFER_SIZE]; 
              bufferPointer = bytesRead = 0; 
          } 
    
          public String readLine() throws IOException 
          { 
              byte[] buf = new byte[64]; // line length 
              int cnt = 0, c; 
              while ((c = read()) != -1) 
              { 
                  if (c == '\n') 
                      break; 
                  buf[cnt++] = (byte) c; 
              } 
              return new String(buf, 0, cnt); 
          } 
    
          public int nextInt() throws IOException 
          { 
              int ret = 0; 
              byte c = read(); 
              while (c <= ' ') 
                  c = read(); 
              boolean neg = (c == '-'); 
              if (neg) 
                  c = read(); 
              do
              { 
                  ret = ret * 10 + c - '0'; 
              }  while ((c = read()) >= '0' && c <= '9'); 
    
              if (neg) 
                  return -ret; 
              return ret; 
          } 
    
          public long nextLong() throws IOException 
          { 
              long ret = 0; 
              byte c = read(); 
              while (c <= ' ') 
                  c = read(); 
              boolean neg = (c == '-'); 
              if (neg) 
                  c = read(); 
              do { 
                  ret = ret * 10 + c - '0'; 
              } 
              while ((c = read()) >= '0' && c <= '9'); 
              if (neg) 
                  return -ret; 
              return ret; 
          } 
    
          public double nextDouble() throws IOException 
          { 
              double ret = 0, div = 1; 
              byte c = read(); 
              while (c <= ' ') 
                  c = read(); 
              boolean neg = (c == '-'); 
              if (neg) 
                  c = read(); 
    
              do { 
                  ret = ret * 10 + c - '0'; 
              } 
              while ((c = read()) >= '0' && c <= '9'); 
    
              if (c == '.') 
              { 
                  while ((c = read()) >= '0' && c <= '9') 
                  { 
                      ret += (c - '0') / (div *= 10); 
                  } 
              } 
    
              if (neg) 
                  return -ret; 
              return ret; 
          } 
    
          private void fillBuffer() throws IOException 
          { 
              bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
              if (bytesRead == -1) 
                  buffer[0] = -1; 
          } 
    
          private byte read() throws IOException 
          { 
              if (bufferPointer == bytesRead) 
                  fillBuffer(); 
              return buffer[bufferPointer++]; 
          } 
    
          public void close() throws IOException 
          { 
              if (din == null) 
                  return; 
              din.close(); 
          } 
      }
    static  PrintWriter out=new PrintWriter(System.out);
    static int int_max=Integer.MAX_VALUE;
    static int int_min=Integer.MIN_VALUE;
    static long long_max=Long.MAX_VALUE;
    static long long_min=Long.MIN_VALUE;
  }
  // Thank You !