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.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.BufferedReader;
  import java.util.*;
  
  public class D {
  	private static final FastReader fs = new FastReader();
  	private static final PrintWriter out = new PrintWriter(System.out);
  	private static long m = 1_000_000_009;
  	private static long p = 31;
  	private static long mod = 1_000_000_007;
  	
  	private static class dsu{
  		int[] par,size;
  		public dsu(int n) {
  			this.par = new int[n];
  			this.size = new int[n];
  			for(int i = 0; i < n; i++) {
  				this.par[i] = i;
  				this.size[i] = 1;
  			}
  		}
  		
  		public int findPar(int u) {
  			if(u == this.par[u])
  				return u;
  			else {
  				this.par[u] = findPar(this.par[u]);
  				return this.par[u];
  			}
  		}
  		
  		public void merge(int x,int y) {
  			x = findPar(x);
  			y = findPar(y);
  			if(x == y)
  				return;
  			else if(size[x] >= size[y]) {
  				par[y] = x;
  				size[x] += size[y];
  			}
  			else {
  				par[x] = y;
  				size[y] += size[x];
  			}
  		}
  	}
  	
  	
  	private static void solve() throws Exception {
  		int n = fs.nextInt(), m1 = fs.nextInt(), m2 = fs.nextInt();
  		dsu d1 = new dsu(n), d2 = new dsu(n);
  		for(int i = 0; i < m1; i++) {
  			int u = fs.nextInt()-1;
  			int v = fs.nextInt()-1;
  			d1.merge(u,  v);
  		}
  		for(int i = 0; i < m2; i++) {
  			int u = fs.nextInt()-1;
  			int v = fs.nextInt()-1;
  			d2.merge(u,  v);
  		}
  		ArrayList<int []> ans = new ArrayList<>();
  		for(int i = 0; i < n; i++) {
  			for(int j = i+1; j < n; j++) {
  				if(d1.findPar(i) != d1.findPar(j) && d2.findPar(i) != d2.findPar(j)){
  					ans.add(new int[] {i+1, j+1});
  					d1.merge(i, j);
  					d2.merge(i, j);
  				}
  			}
  		}
  		out.println(ans.size());
  		for(int[] ele : ans)
  			out.println(ele[0] + " " + ele[1]);
  		
  	}
   
  	public static void main(String[] args) {
  		Thread t = new Thread(null, null, "", 1 << 28) {
  			public void run() {
  				int test_case = 1;
  				//test_case = fs.nextInt();
  				for (int cs = 1; cs <= test_case; cs++) {
  					try {
  						solve();
  					} catch (Exception e) {
  						// TODO Auto-generated catch block
  						e.printStackTrace();
  					}
  				}
  				out.close();
  			}
  		};
  		t.start();
  		try {
  			t.join();
  		} catch (InterruptedException e) {
  			e.printStackTrace();
  		}
  	}
   
  	private 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;
  		}
   
  		int[] readintarray(int n) {
  			int res[] = new int[n];
  			for (int i = 0; i < n; i++)
  				res[i] = nextInt();
  			return res;
  		}
   
  		long[] readlongarray(int n) {
  			long res[] = new long[n];
  			for (int i = 0; i < n; i++)
  				res[i] = nextLong();
  			return res;
  		}
  	}
   
  	public static class pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>> implements Comparable<pair<T1, T2>> {
  		T1 ff;
  		T2 ss;
   
  		public pair(T1 ff, T2 ss) {
  			this.ff = ff;
  			this.ss = ss;
  		}
   
  		public int compareTo(pair<T1, T2> o) {
  			if (ff == o.ff)
  				return ss.compareTo(o.ss);
  			return ff.compareTo(o.ff);
  		}
  	}
  	
  	private static int max(int... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from maxFunction with Integer return type. Reason is :: Argument length cannot be zero");
  		int maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.max(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static int min(int... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from minFunction with Integer return type. Reason is :: Argument length cannot be zero");
  		int maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.min(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static long max(long... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from maxFunction with Long return type. Reason is :: Argument length cannot be zero");
  		long maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.max(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static long min(long... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from minFunction with Long return type. Reason is :: Argument length cannot be zero");
  		long maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.min(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static int abs(int a) {
  		return a >= 0 ? a : -a;
  	}
  	
  	private static int abs(int a, int b) {
  		return a-b >= 0 ? a-b : b-a;
  	}
  	
  	private static long abs(long a) {
  		return a >= 0 ? a : -a;
  	}
  	
  	private static long abs(long a, long b) {
  		return a-b >= 0 ? a-b : b-a;
  	}
  	
  	private static int power(int base, int exponent) {
  		int res = 1;
  		while(exponent > 0) {
  			if((exponent & 1) != 0)
  				res *= base;
  			exponent >>= 1;
  			base *= base;
  		}
  		return res;
  	}
  	
  	private static long power(long base, long exponent) {
  		long res = 1;
  		while(exponent > 0) {
  			if((exponent & 1) != 0)
  				res *= base;
  			exponent >>= 1;
  			base *= base;
  		}
  		return res;
  	}
  	
  	private static long mPower(long base, long exponent) throws Exception {
  		long res = 1;
  		base %= mod;
  		while(exponent > 0) {
  			if((exponent & 1) != 0)
  				res = mul(res, base);
  			exponent >>= 1;
  			base = mul(base, base);
  		}
  		return res;
  	}
  	
  	private static long mul(long... arg) throws Exception {
  		long mulRes = 1;
  		for(long arg0 : arg)
  			mulRes = (mulRes % mod * arg0 % mod) % mod;
  		return mulRes;
  	}
  	
  	private static long add(long... arg) throws Exception {
  		long mulRes = 1;
  		for(long arg0 : arg)
  			mulRes = (mulRes % mod + arg0 % mod) % mod;
  		return mulRes;
  	}
  	
  	private static long sub(long... arg) throws Exception {
  		long mulRes = 1;
  		for(long arg0 : arg)
  			mulRes = ((mulRes % mod - arg0 % mod) % mod + mod) % mod;
  		return mulRes;
  	}
  }