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: //Utilities
  import java.io.*;
  import java.util.*;
  
  public class D {
  	static int n;
  	static int[] m = new int[3];
  	static int[][] ds;
  	static int[][] rank;
  	static ArrayList<Integer> resX, resY;
  	static int u, v;
  	
  	public static void main(String[] args) throws IOException {
  		n = in.iscan(); m[1] = in.iscan(); m[2] = in.iscan();
  		ds = new int[3][1005]; rank = new int[3][1005];
  		for (int i = 0; i < 1005; i++) {
  			ds[1][i] = ds[2][i] = i;
  		}
  		for (int i = 0; i < m[1]; i++) {
  			u = in.iscan(); v = in.iscan();
  			union(1, u, v);
  		}
  		for (int i = 0; i < m[2]; i++) {
  			u = in.iscan(); v = in.iscan();
  			union(2, u, v);
  		}
  		resX = new ArrayList<Integer>(); resY = new ArrayList<Integer>();
  		for (int i = 1; i <= n; i++) {
  			for (int j = i+1; j <= n; j++) {
  				if (find(1, i) != find(1, j) && find(2, i) != find(2, j)){
  					union(1, i, j); union(2, i, j);
  					resX.add(i); resY.add(j);
  				}
  			}
  		}
  		out.println(resX.size());
  		for (int i = 0; i < resX.size(); i++) {
  			out.println(resX.get(i) + " " + resY.get(i));
  		}
  		out.close();
  	} 
  	
  	static void union(int c, int x, int y) {
  		int rx = find(c, x), ry = find(c, y);
  		if (rx == ry) return;
  		if (rank[c][rx] < rank[c][ry]) {
  			ds[c][rx] = ry;
  		}
  		else if (rank[c][rx] == rank[c][ry]) {
  			ds[c][rx] = ry;
  			rank[c][ry]++;
  		}
  		else {
  			ds[c][ry] = rx;
  		}
  		return;
  	}
  	
  	static int find(int c, int x) {
  		if (x == ds[c][x]) {
  			return x;
  		}
  		return find(c, ds[c][x]);
  	}
  	
  	static INPUT in = new INPUT(System.in);
  	static PrintWriter out = new PrintWriter(System.out);
  	private static class INPUT {
  
  		private InputStream stream;
  		private byte[] buf = new byte[1024];
  		private int curChar, numChars;
  
  		public INPUT (InputStream stream) {
  			this.stream = stream;
  		}
  
  		public INPUT (String file) throws IOException {
  			this.stream = new FileInputStream (file);
  		}
  
  		public int cscan () throws IOException {
  			if (curChar >= numChars) {
  				curChar = 0;
  				numChars = stream.read (buf);
  			}
  			
  			if (numChars == -1)
  				return numChars;
  
  			return buf[curChar++];
  		}
  
  		public int iscan () throws IOException {
  			int c = cscan (), sgn = 1;
  			
  			while (space (c))
  				c = cscan ();
  
  			if (c == '-') {
  				sgn = -1;
  				c = cscan ();
  			}
  
  			int res = 0;
  
  			do {
  				res = (res << 1) + (res << 3);
  				res += c - '0';
  				c = cscan ();
  			}
  			while (!space (c));
  
  			return res * sgn;
  		}
  
  		public String sscan () throws IOException {
  			int c = cscan ();
  			
  			while (space (c))
  				c = cscan ();
  
  			StringBuilder res = new StringBuilder ();
  
  			do {
  				res.appendCodePoint (c);
  				c = cscan ();
  			}
  			while (!space (c));
  
  			return res.toString ();
  		}
  
  		public double dscan () throws IOException {
  			int c = cscan (), sgn = 1;
  			
  			while (space (c))
  				c = cscan ();
  
  			if (c == '-') {
  				sgn = -1;
  				c = cscan ();
  			}
  
  			double res = 0;
  
  			while (!space (c) && c != '.') {
  				if (c == 'e' || c == 'E')
  					return res * UTILITIES.fast_pow (10, iscan ());
  				
  				res *= 10;
  				res += c - '0';
  				c = cscan ();
  			}
  
  			if (c == '.') {
  				c = cscan ();
  				double m = 1;
  
  				while (!space (c)) {
  					if (c == 'e' || c == 'E')
  						return res * UTILITIES.fast_pow (10, iscan ());
  
  					m /= 10;
  					res += (c - '0') * m;
  					c = cscan ();
  				}
  			}
  
  			return res * sgn;
  		}
  
  		public long lscan () throws IOException {
  			int c = cscan (), sgn = 1;
  			
  			while (space (c))
  				c = cscan ();
  
  			if (c == '-') {
  				sgn = -1;
  				c = cscan ();
  			}
  
  			long res = 0;
  
  			do {
  				res = (res << 1) + (res << 3);
  				res += c - '0';
  				c = cscan ();
  			}
  			while (!space (c));
  
  			return res * sgn;
  		}
  
  		public boolean space (int c) {
  			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  		}
  	}
  
  	public static class UTILITIES {
  
  		static final double EPS = 10e-6;
  		
  		public static void sort(int[] a, boolean increasing) {
  			ArrayList<Integer> arr = new ArrayList<Integer>();
  			int n = a.length;
  			for (int i = 0; i < n; i++) {
  				arr.add(a[i]);
  			}
  			Collections.sort(arr);
  			for (int i = 0; i < n; i++) {
  				if (increasing) {
  					a[i] = arr.get(i);
  				}
  				else {
  					a[i] = arr.get(n-1-i);
  				}
  			}
  		}
  		
  		public static void sort(long[] a, boolean increasing) {
  			ArrayList<Long> arr = new ArrayList<Long>();
  			int n = a.length;
  			for (int i = 0; i < n; i++) {
  				arr.add(a[i]);
  			}
  			Collections.sort(arr);
  			for (int i = 0; i < n; i++) {
  				if (increasing) {
  					a[i] = arr.get(i);
  				}
  				else {
  					a[i] = arr.get(n-1-i);
  				}
  			}
  		}
  		
  		public static void sort(double[] a, boolean increasing) {
  			ArrayList<Double> arr = new ArrayList<Double>();
  			int n = a.length;
  			for (int i = 0; i < n; i++) {
  				arr.add(a[i]);
  			}
  			Collections.sort(arr);
  			for (int i = 0; i < n; i++) {
  				if (increasing) {
  					a[i] = arr.get(i);
  				}
  				else {
  					a[i] = arr.get(n-1-i);
  				}
  			}
  		}
  
  		public static int lower_bound (int[] arr, int x) {
  			int low = 0, high = arr.length, mid = -1;
  
  			while (low < high) {
  				mid = (low + high) / 2;
  
  				if (arr[mid] >= x)
  					high = mid;
  				else
  					low = mid + 1;
  			}
  
  			return low;
  		}
  
  		public static int upper_bound (int[] arr, int x) {
  			int low = 0, high = arr.length, mid = -1;
  
  			while (low < high) {
  				mid = (low + high) / 2;
  
  				if (arr[mid] > x)
  					high = mid;
  				else
  					low = mid + 1;
  			}
  
  			return low;
  		}
  
  		public static long gcd (long a, long b) {
  			return b == 0 ? a : gcd (b, a % b);
  		}
  
  		public static long lcm (long a, long b) {
  			return a * b / gcd (a, b);
  		}
  
  		public static long fast_pow_mod (long b, long x, int mod) {
  			if (x == 0) return 1;
  			if (x == 1) return b;
  			if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;
  
  			return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;
  		}
  
  		public static int fast_pow (int b, int x) {
  			if (x == 0) return 1;
  			if (x == 1) return b;
  			if (x % 2 == 0) return fast_pow (b * b, x / 2);
  
  			return b * fast_pow (b * b, x / 2);
  		}
  
  		public static long choose (long n, long k) {
  			k = Math.min (k, n - k);
  			long val = 1;
  
  			for (int i = 0; i < k; ++i)
  				val = val * (n - i) / (i + 1);
  
  			return val;
  		}
  
  		public static long permute (int n, int k) {
  			if (n < k) return 0;
  			long val = 1;
  
  			for (int i = 0; i < k; ++i)
  				val = (val * (n - i));
  
  			return val;
  		}
  		
  		// start of permutation and lower/upper bound template
  		public static void nextPermutation(int[] nums) {
  		    //find first decreasing digit
  		    int mark = -1;
  		    for (int i = nums.length - 1; i > 0; i--) {
  		        if (nums[i] > nums[i - 1]) {
  		            mark = i - 1;
  		            break;
  		        }
  		    }
  		 
  		    if (mark == -1) {
  		        reverse(nums, 0, nums.length - 1);
  		        return;
  		    }
  		 
  		    int idx = nums.length-1;
  		    for (int i = nums.length-1; i >= mark+1; i--) {
  		        if (nums[i] > nums[mark]) {
  		            idx = i;
  		            break;
  		        }
  		    }
  		 
  		    swap(nums, mark, idx);
  		 
  		    reverse(nums, mark + 1, nums.length - 1);
  		}
  		 
  		public static void swap(int[] nums, int i, int j) {
  		    int t = nums[i];
  		    nums[i] = nums[j];
  		    nums[j] = t;
  		}
  		 
  		public static void reverse(int[] nums, int i, int j) {
  		    while (i < j) {
  		        swap(nums, i, j);
  		        i++;
  		        j--;
  		    }
  		}
  		
  		static int lower_bound (int[] arr, int hi, int cmp) {
  			int low = 0, high = hi, mid = -1;
  			while (low < high) {
  				mid = (low + high) / 2;
  				if (arr[mid] >= cmp) high = mid;
  				else low = mid + 1;
  			}
  			return low;
  		}
  	 
  		static int upper_bound (int[] arr, int hi, int cmp) {
  			int low = 0, high = hi, mid = -1;
  			while (low < high) {
  				mid = (low + high) / 2;
  				if (arr[mid] > cmp) high = mid;
  				else low = mid + 1;
  			}
  			return low;
  		}
  		// end of permutation and lower/upper bound template
  	}
  }
  