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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  
  //import Number_theory.pair;
  
  import java.util.PriorityQueue;
  import java.util.Queue;
  import java.util.Stack;
  import java.util.StringTokenizer;
  import java.util.TreeMap;
  import java.util.TreeSet;
  
  //import graph_representation.edge;
  public class hacker49 {
  	public static int r1=0;
  	static class FastReader 
      { 
          BufferedReader br; 
          StringTokenizer st; 
    
          public FastReader() 
          { 
              br = new BufferedReader(new
                       InputStreamReader(System.in)); 
          } 
    
          String next() 
          { 
              while (st == null || !st.hasMoreElements()) 
              { 
                  try
                  { 
                      st = new StringTokenizer(br.readLine()); 
                  } 
                  catch (IOException  e) 
                  { 
                      e.printStackTrace(); 
                  } 
              } 
              return st.nextToken(); 
          } 
    
          int nextInt() 
          { 
              return Integer.parseInt(next()); 
          } 
    
          long nextLong() 
          { 
              return Long.parseLong(next()); 
          } 
    
          double nextDouble() 
          { 
              return Double.parseDouble(next()); 
          } 
    
          String nextLine() 
          { 
              String str = ""; 
              try
              { 
                  str = br.readLine(); 
              } 
              catch (IOException e) 
              { 
                  e.printStackTrace(); 
              } 
              return str; 
          } 
      } 
  //static 	ArrayList<Integer>[] f=new ArrayList[200001];
  static 	int[] deg=new int[100001];
  static class y{
  	private int a;
  	private int b;
  	y(int a,int b) {
  		this.a=a;
  		this.b=b;
  	}
  }
  	static HashMap<Long,Integer> e=new HashMap<>();
  	public static void main(String[] args) {
  		OutputStream outputStream =System.out;
  	    PrintWriter out =new PrintWriter(outputStream);
  		FastReader s=new FastReader();
  int n=s.nextInt();
  int m1=s.nextInt();
  int m2=s.nextInt();
  
  for(int i=0;i<m1;i++) {
  	int x=s.nextInt();
  	int y=s.nextInt();
  //	par1[x]=y;
  	int g1=get1(x);
  	int g2=get1(y);
  	par1[g1]=g2;
  //	e1[x].add(y);
  //	e1[y].add(x);
  }
  for(int i=0;i<m2;i++) {
  	int x=s.nextInt();
  	int y=s.nextInt();
  	int g1=get2(x);
  	int g2=get2(y);
  	par2[g1]=g2;
  }
  ArrayList<pair7> e=new ArrayList<>();
  
  out:for(int i=1;i<=n;i++) {
  	for(int j=i;j<=n;j++) {
  	
  			int g1=get1(i);
  			int g2=get1(j);
  			int g3=get2(i);
  			int g4=get2(j);
  			
  			if(g1!=g2 && g3!=g4) {
  //				e1[i].add(j);
  //				e1[j].add(i);
  //				e2[i].add(j);
  //				e2[j].add(i);
  				par1[g1]=g2;
  				par2[g3]=g4;
  m1++;
  m2++;
  if(m1==n || m2==n) {
  	break out;
  }
  				e.add(new pair7(i,j));
  //				out.println(g1+" "+g2+" "+g3+" "+g4);
  			}
  		
  	}
  }
  out.println(e.size());
  for(int i=0;i<e.size();i++) {
  	out.println(e.get(i).a+" "+e.get(i).b);
  }
  
  
  out.close();
  	}
  	static int get1(int t) {
  		if(par1[t]==0) {
  			return t;
  		}
  		return par1[t]=get1(par1[t]);
  	}
  	static int get2(int t) {
  		if(par2[t]==0) {
  			return t;
  		}
  		return par2[t]=get2(par2[t]);
  	}
  	static int[] par1=new int[1001];
  	static int[] par2=new int[1001];
  	static int[] d1=new int[1001];
  	static int[] d2=new int[1001];
  	static HashSet<Integer>[] e1=new HashSet[1001];
  	static HashSet<Integer>[] e2=new HashSet[1001];
  	static  class pair7{
  		private int a;
  		private int b;
  		pair7(int a,int b){
  			this.a=a;
  			this.b=b;
  		}
  	}
  	public static int[] pre=new int[5000001];
  	public static  int[] arr=new int[5000001];
  	public static int[] is_prime=new int[5000001];
  	public static ArrayList<Long> primes=new ArrayList<>();
  	public static void sieve() {
  		long maxN=5000000;
  		for(long i=1;i<=maxN;i++) {
  			is_prime[(int) i]=1;
  		}
  		is_prime[0]=0;
  		is_prime[1]=0;
  		for(long i=2;i*i<=maxN;i++) {
  			if(is_prime[(int) i]!=0) {
  //				primes.add((int) i);
  				long c=1;
  				for(long j=i*i;j<=maxN;j+=i) {
  					is_prime[(int) j]++;
  				}
  			}
  		}
  		
  		for(long i=2;i<=maxN;i++) {
  			is_prime[(int) i]=is_prime[(int) (i-1)]+is_prime[(int) i];
  		}
  //		int count=0;
  //		for(long i=1;i<=maxN;i++) {
  //			if(is_prime[(int) i]==1) {
  //				count++;
  //			}
  //			if(is_prime[count]==1) {
  //				arr[(int) i]=1;
  //			}else {
  //				arr[(int)i]=0;
  //			}
  //		}
  	}
  	
  	public static long GCD(long a,long b) {
  		
  		if(b==(long)0) {
  			return a;
  		}
  		return GCD(b , a%b);
  	}
  	static long c=0;
  	public static long res=1;
  	public static void prime_factorization(long n) {
  		for(long i=2;i*i<=n;i++) {
  			if(n%i==0) {
  				long count=0;
  				while(n%i==0) {
  					count++;
  					n/=i;
  				}
  //			prime_pairs.add(new pair(i,count));
  //			res*=(count+1);
  				c+=(count);
  			}
  		}
  		if(n>1) {
  //			prime_pairs.add(new pair(n,1));
  //		res*=2;
  			c+=(1);
  		}
  		
  	}
  	static long ans1=0;
  	static long ans2=1;
  	static long curr=Long.MAX_VALUE;
  	static long count3=0;
  	static long[] val=new long[100001];
  	static HashMap<Long,Long> e5=new HashMap<>();
  	static int[] visited=new int[100001];
  	static ArrayList<Integer> r2=new ArrayList<>();
  	static ArrayList<Integer> SCC=new ArrayList<>();
  	public static void kosadfs(int node) {
  		visited[node]=1;
  		SCC.add(node);
  		if(curr>val[node]) {
  			count3=1;
  			curr=val[node];
  		}else if(curr==val[node]){
  			count3++;
  		}
  	
  		for(int i=0;i<f1[node].size();i++) {
  			if(visited[(int)f1[node].get(i)]==0) {
  				kosadfs((int)f1[node].get(i));
  			}
  		}
  	}
  	public static void kosarajus_algo(int n) {
  		for(int i=1;i<=n;i++) {
  			if(visited[i]==0) {
  				time(i);
  			}
  		}
  //		time(1);
  		for(int i=1;i<=n;i++) {
  			visited[i]=0;
  		}
  		for(int i=n-1;i>=0;i--) {
  			if(visited[r2.get(i)]==0) {
  				SCC.clear();
  				curr=Long.MAX_VALUE;
  				count3=0;
  				kosadfs(r2.get(i));
  				ans1+=curr;
  //				count3=0;
  				ans2=(ans2*count3)%mod;
  				
  			}
  		}
  	}
  	public static void time(int v) {
  		visited[v]=1;
  		for(int i=0;i<f[v].size();i++) {
  			if(visited[(int)f[v].get(i)]==0) {
  				time((int)f[v].get(i));
  			}
  		}
  		r2.add(v);
  	}
  
  
  
  
  
  	public static int upper_bound(long[] a ,long x,  int g,int n ) {
  		int l=g;
  		int r=n;
  		while(r>l+1) {
  			int mid=(l+r)/2;
  			if(a[mid]>=x) {
  				r=mid;
  			}else {
  				l=mid;
  			}
  		}
  		return r;
  				
  	}
  
  //	
  //	
  	public static int lower_bound(long[] b,long x,int g,int n) {
  		int l=g;
  		int r=n;
  		while(r>l+1) {
  			int mid=(l+r)/2;
  			if(b[mid]<=x) {
  				l=mid;
  			}else {
  				r=mid;
  			}
  		}
  		return l;
  				
  	}
  	
  
  	static int[] vis1=new int[100001];
  	static long count=0;
  	static void dfs(int node) {
  		vis1[node]=1;
  		count++;
  		for(int i=0;i<f[node].size();i++) {
  			if(vis1[f[node].get(i)]==0)
  			dfs(f[node].get(i));
  		}
  		
  	}
  	static ArrayList<Integer>[] f=new ArrayList[100001];
  	static ArrayList<Integer>[] f1=new ArrayList[100001];
  	public static long binary_exponentiation_1(long a,long n) {
  		long res=1;
  		while(n>0) {
  			if(n%2!=0) {
  				res=((res)%(1000000007) * (a)%(1000000007))%(1000000007);
  				n--;
  				
  			}else {
  				a=((a)%(1000000007) *(a)%(1000000007))%(1000000007);
  				n/=2;
  			}
  		}
  		return (res)%(1000000007);
  		
  	}
  	public static long im(long a) {
  		return binary_exponentiation_1(a,mod-2)%mod;
  	}
  	public static long[] fac=new long[10000001];
  	public static void ff() {
  		fac[0]=1;
  		fac[1]=1;
  		for(int i=2;i<=200000;i++) {
  			fac[i]=(fac[i-1]*i)%(mod);
  		}
  	}
  	static int l=1;
  	static int r=1;
  	static int[][] vis=new int[301][301];
  	static boolean isvalid(int x,int y,int n,int m) {
  		if(x>=1 && x<=n && y>=1 && y<=m) {
  			return true;
  		}
  	return false;
  	}
  static void dfs(int n,int m,int count,int g) {
  System.out.print(l+" "+r+" ");
  vis[l][r]=1;
  if(count==g) {
  	return;
  }
  if(isvalid(l,r+1,n,m) && vis[l][r+1]==0) {
  	r++;
  	dfs(n,m,count+1,g);
  	
  }else if(isvalid(l,r-1,n,m) && vis[l][r-1]==0) {
  	r--;
  	dfs(n,m,count+1,g);
  //	l++;
  }else {
  	l++;
  	dfs(n,m,count+1,g);
  //	l--;
  }
  
  }
  	public static long be(long a,long n) {
  		long res=1;
  		while(n>0) {
  			if(n%2!=0) {
  //				res=((res)%(1000000007) * (a)%(1000000007))%(1000000007);
  				res=res*a;
  				n--;
  			}else {
  //				a=((a)%(1000000007) *(a)%(1000000007))%(1000000007);
  				a=a*a;
  				n/=2;
  			}
  		}
  //		return (res)%(1000000007);
  		return res;
  	}
  //	
  	static class pair2 implements Comparable<pair2>{
  //		private int a;
  //		private int b;
  		private long a;
  		private long  b;
  		pair2(long a,long b){
  			this.a=a;
  			this.b=b;
  //			this.c=c;
  		}
  		public int compareTo(pair2 o) {
  //			
  //			return Long.compare(o.c,this.c);
  		return Long.compare(this.a, o.a);			
  		}
  		
  	}
  	
  
  
  		
  	
  	
  	
  	public static long[] merge_sort(long[] A, int start, int end) {
  		if (end > start) {
  			int mid = (end + start) / 2;
  			long[] v = merge_sort(A, start, mid);
  			long[] o = merge_sort(A, mid + 1, end);
  			return (merge(v, o));
  		} else {
  			long[] y = new long[1];
  			y[0] = A[start];
  			return y;
  		}
  	}
  	public static long[] merge(long a[], long b[]) {
  //		int count=0;
  		long[] temp = new long[a.length + b.length];
  		int m = a.length;
  		int n = b.length;
  		int i = 0;
  		int j = 0;
  		int c = 0;
  		while (i < m && j < n) {
  			if (a[i] < b[j]) {
  				temp[c++] = a[i++];
  			
  			} else {
  				temp[c++] = b[j++];
  			}
  		}
  		while (i < m) {
  			temp[c++] = a[i++];
  		}
  		while (j < n) {
  			temp[c++] = b[j++];
  		}
  		return temp;
  	}
  	
  	public static int[] merge_sort1(int[] A, int start, int end) {
  		if (end > start) {
  			int mid = (end + start) / 2;
  			int[] v = merge_sort1(A, start, mid);
  			int[] o = merge_sort1(A, mid + 1, end);
  			return (merge1(v, o));
  		} else {
  			int[] y = new int[1];
  			y[0] = A[start];
  			return y;
  		}
  	}
  	public static int[] merge1(int a[], int b[]) {
  //		int count=0;
  		int[] temp = new int[a.length + b.length];
  		int m = a.length;
  		int n = b.length;
  		int i = 0;
  		int j = 0;
  		int c = 0;
  		while (i < m && j < n) {
  			if (a[i] < b[j]) {
  				temp[c++] = a[i++];
  			
  			} else {
  				temp[c++] = b[j++];
  			}
  		}
  		while (i < m) {
  			temp[c++] = a[i++];
  		}
  		while (j < n) {
  			temp[c++] = b[j++];
  		}
  		return temp;
  	}
  	
  	static long mod=1000000007;
  	
  
  
  
  
  //	for(int i=2;i<=100000;i++) {
  		
  	
  }