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.lang.reflect.Array;
  import java.math.RoundingMode;
  import java.text.DecimalFormat;
  import java.util.*;
  
  
  
  public class copy{
      public static int find(int a,int[] parent)
      {
          if(parent[a]==a)
              return a;
          return find(parent[a],parent);
      }
  
      public static void union(int a,int b,int[] parent, int[] rank)
      {
          int x=find(a,parent);
          int y=find(b,parent);
          if(rank[x]>rank[y])
          {
              parent[y]=x;
  
          }
          else if(rank[y]>rank[x])
          {
              parent[x]=y;
  
          }
          else
          {
              parent[y]=x;
              rank[x]++;
  
          }
      }
  
      static double answer;
  
      public static int check(ArrayList<ArrayList<Integer>> edges,int x,int parent,int[] statues,int n)
      {
          ArrayList<Integer> arr=new ArrayList<>();
          for(int i:edges.get(x))
          {
              if(i!=parent)
              {
                  arr.add(check(edges,i,x,statues,n));
              }
          }
          int sum=0;
          for(int i=arr.size()-1;i>=0;i--)
          {
  
              answer+=((long)arr.get(i)*(long)sum*(long)statues[x])/((double)n*(double)(n-1));
              sum+=arr.get(i);
          }
          answer+=((long)sum*(long)statues[x])/((double)n*(double)(n-1));
          //System.out.println(x+" "+sum);
          return 1+sum;
      }
  
      public static boolean check(int X,int a,int b)
      {
          System.out.println(X);
  
          if(X==1)
              return true;
          boolean status=false;
          if(X%a==0 && a!=1)
              status=status || check(X/a,a,b);
          if(X-b>=1 && b!=0)
              status=status || check(X-b,a,b);
  
          return status;
  
  
      }
  
      public static int check(long xor,ArrayList<Long> sum,int low,int N)
      {
          int l=low;
          int r=N-1;
          while(l<=r)
          {
              int mid=(l+r)/2;
              if(sum.get(mid)==xor)
              {
                  return mid;
              }
              else
                  r=mid-1;
          }
  
          return 0;
      }
  
      public static void merge(int l,int mid,int r,cp[] arr,HashMap<Integer,Integer> before)
      {
          int N=mid-l+1,M=r-mid;
          cp[] arr1=new cp[mid-l+1];
          cp[] arr2=new cp[r-mid];
          cp[] arr3=new cp[N+M];
          for(int i=l;i<=mid;i++)
              arr1[i-l]=arr[i];
          for(int i=mid+1;i<=r;i++)
              arr2[i-mid-1]=arr[i];
          int left=0,right=0,k=0;
          while(left<N && right<M)
          {
  
              if(arr1[left].a<arr2[right].a)
              {
                  arr3[k++]=arr1[left++];
              }
              else
              {
  
                  before.put(arr2[right].b,before.getOrDefault(arr2[right].b,0)+N-left);
                  count+=N-left;
                  arr3[k++]=arr2[right++];
              }
          }
  
          while(left<N)
          {
              arr3[k++]=arr1[left++];
          }
  
          while(right<M)
          {
              arr3[k++]=arr2[right++];
          }
  
          for(int i=l;i<=r;i++)
              arr[i]=arr3[i-l];
  
  
  
      }
  
      public static void inv(HashMap<Integer,Integer> before,int l,int r,cp[] arr)
      {
          if(l==r)
              return;
          int mid=(l+r)/2;
          inv(before,l,mid,arr);
          inv(before,mid+1,r,arr);
          merge(l,mid,r,arr,before);
      }
      static long count=0;
      public static int check(ArrayList<Long> arr,long X,int low,int N,long mod)
      {
          int l=low;
          int r=N;
          while(l<=r)
          {
              int mid=l+(r-l)/2;
              if(((arr.get(mid)-arr.get(low-1)))/(long)(mid-low+1)<X)
              {
                  if(mid+1<=N &&  ((arr.get(mid+1)-arr.get(low-1)))/(long)(mid-low+2)<X)
                      l=mid+1;
                  else
                      return mid;
              }
              else
                  r=mid-1;
          }
  
          return -1;
      }
  
      public static void check(ArrayList<ArrayList<Integer>> arr,int x,int parent,ArrayList<Integer> answer)
      {
          answer.add(x);
          for(int i:arr.get(x))
          {
              if(i!=parent)
              {
                  check(arr,i,x,answer);
                  answer.add(x);
              }
          }
  
      }
  
      static long binpow( long a,  long b,  long m) {
          a %= m;
          long  res = 1;
          while (b > 0) {
              if ((b & 1)==1)
                  res = res * a % m;
              a = a * a % m;
              b >>= 1;
          }
          return res;
      }
      public static int check(int N,int a,int b,int c,int[] dp)
      {
          if(dp[N]!=-2)
              return dp[N];
          if(N==0)
              return 0;
  
          int a1=-1,a2=-1,a3=-1;
          if(N>=a)
              a1=check(N-a,a,b,c,dp);
          if(N>=b)
              a2=check(N-b,a,b,c,dp);
          if(N>=c)
              a3=check(N-c,a,b,c,dp);
          if(a1==-1 && a2==-1 && a3==-1)
              dp[N]=-1;
          else
              dp[N]= 1+Math.max(a1,Math.max(a2,a3));
          return dp[N];
      }
  
      static int curr=0;
      public static int check(ArrayList<ArrayList<Integer>> arr,int x,int parent)
      {
          int total=Integer.MIN_VALUE;
          int max1=0,max2=0;
          for(int i:arr.get(x))
          {
              if(i==parent)
                  continue;
              curr=0;
              total=Math.max(total,check(arr,i,x));
              if(curr>max1)
              {
                  max2=max1;
                  max1=curr;
              }
              else if(curr>max2)
                  max2=curr;
  
  
          }
          total=Math.max(total,max1+max2);
          curr=max1+1;
          return total;
      }
  
      public static long gcd(long a,long b)
      {
          if(a==0)
              return b;
  
          return gcd(b%a,a);
      }
  
  
      public static int check(ArrayList<Double> arr,double number,int N)
      {
          int l=0;
          int r=N;
          while(l<=r)
          {
              int mid=(l+r)/2;
              if(number>=arr.get(mid))
              {
                  if(mid+1<=N && arr.get(mid+1)<=number)
                      l=mid+1;
                  else
                      return mid;
              }
              else
                  r=mid-1;
              //System.out.println("hello");
          }
  
          return 0;
      }
  
  
      public static int check(ArrayList<String> arr)
      {
          int ans=Integer.MAX_VALUE;
          ArrayList<Character> copy=new ArrayList<>();
          for(char ch='a';ch<='z';ch++)
          {
              int s1=0;
              for(String s:arr)
                  if(s.indexOf(ch)!=-1)
                      ++s1;
                  if(s1>1)
                  {
                      copy.add(ch);
                  }
  
          }
          if(copy.size()==0) {
              for (char ch = 'a'; ch <= 'z'; ch++) {
                  int s1 = 0, s2 = 0;
                  for (String s : arr)
                      if (s.indexOf(ch) != -1)
                          s1 += s.length();
                      else
                          s2 += s.length();
  
                  //System.out.println(ch+" "+s1+" "+s2);
                  ans = Math.min(ans, Math.abs(s1 - s2));
  
              }
          }
          else
          {
              for (char ch:copy) {
                  int s1 = 0, s2 = 0;
                  for (String s : arr)
                      if (s.indexOf(ch) != -1)
                          s1 += s.length();
                      else
                          s2 += s.length();
  
                  //System.out.println(ch+" "+s1+" "+s2);
                  ans = Math.min(ans, Math.abs(s1 - s2));
  
              }
          }
  
          return ans;
      }
  
  
  
  
  
  
  
  
  
  
  
  
  
      public static void main(String[] args)throws IOException
      {
          Reader.init(System.in);
          BufferedWriter output=new BufferedWriter(new OutputStreamWriter(System.out));
          int N=Reader.nextInt();
          int m1=Reader.nextInt();
          int m2=Reader.nextInt();
          int[] parent1=new int[N];
          int[] parent2=new int[N];
          int[] rank1=new int[N];
          int[] rank2=new int[N];
          for(int i=0;i<N;i++)
          {
              parent2[i]=i;
              parent1[i]=i;
          }
          for(int i=1;i<=m1;i++)
          {
              int x=Reader.nextInt();
              int y=Reader.nextInt();
              x-=1;
              y-=1;
              int x1=find(x,parent1);
              int y1=find(y,parent1);
              if(x1!=y1)
                  union(x,y,parent1,rank1);
          }
  
          for(int i=1;i<=m2;i++)
          {
              int x=Reader.nextInt();
              int y=Reader.nextInt();
              x-=1;
              y-=1;
              int x1=find(x,parent2);
              int y1=find(y,parent2);
              if(x1!=y1)
                  union(x,y,parent2,rank2);
          }
          int c=0;
          ArrayList<ArrayList<Integer>> arr=new ArrayList<>();
          for(int i=0;i<N;i++)
          {
              for(int j=0;j<N;j++)
              {
                  int x1=find(i,parent1);
                  int x2=find(j,parent1);
                  int x3=find(i,parent2);
                  int x4=find(j,parent2);
                  if(x1!=x2 &&x3!=x4)
                  {
  
                      ++c;
                      ArrayList<Integer> temp=new ArrayList<>();
                      temp.add(i+1);
                      temp.add(j+1);
                      arr.add(temp);
                      union(i,j,parent1,rank1);
                      union(i,j,parent2,rank2);
                  }
  
              }
          }
  
          output.write(c+"\n");
          for(ArrayList<Integer> temp:arr)
              output.write(temp.get(0)+" "+temp.get(1)+"\n");
          output.flush();
  
      }
  }
  
  class cord
  {
      int x;
      cord next;
      cord(int x)
      {
          this.x=x;
      }
  }
  
  class cp
  {
      int a,b;
      cp(int a,int b)
      {
          this.a=a;
          this.b=b;
  
      }
  }
  
  class sort_cp implements Comparator<cp>
  {
      public int compare(cp o1,cp o2)
      {
          if(o1.b>o2.b)
              return -1;
          else if(o1.b<o2.b)
              return 1;
          else
              return 0;
      }
  }
  class g_node{
      int val;
      long wt;
  
      g_node(int val, long wt)
      {
          this.val = val;
          this.wt = wt;
      }
  }
  class Reader {
      static BufferedReader reader;
      static StringTokenizer tokenizer;
  
      static void init(InputStream input) {
          reader = new BufferedReader(
                  new InputStreamReader(input));
          tokenizer = new StringTokenizer("");
      }
  
      static String next() throws IOException {
          while (!tokenizer.hasMoreTokens()) {
              tokenizer = new StringTokenizer(
                      reader.readLine());
          }
          return tokenizer.nextToken();
      }
  
      static int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
  
      static long nextLong() throws IOException {
          return Long.parseLong(next());
      }
  
      static double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
  }