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.util.*;
  
  public class B {
  
  	static pair[] bo;
  	static int[] f;
  	
  	public static  class UnionFind {                                              
  		int[] p, rank, setSize;
  		int numSets;
  
  		public UnionFind(int N) 
  		{
  			p = new int[numSets = N];
  			rank = new int[N];
  			setSize = new int[N];
  			for (int i = 0; i < N; i++) {  p[i] = i; setSize[i] = 1; }
  		}
  
  		public int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); }
  
  		public boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  
  		public void unionSet(int i, int j) 
  		{ 
  			if (isSameSet(i, j)) 
  				return;
  			numSets--; 
  			int x = findSet(i), y = findSet(j);
  			if(rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
  			else
  			{	p[x] = y; setSize[y] += setSize[x];
  				if(rank[x] == rank[y]) rank[y]++; 
  			} 
  		}
  
  		public int numDisjointSets() { return numSets; }
  
  		public int sizeOfSet(int i) { return setSize[findSet(i)]; }
  	}
  	public static void main(String args[]) throws Exception {
  		Scanner sc = new Scanner(System.in);
  		PrintWriter pw = new PrintWriter(System.out);
  
  		int t = 1;
  		while (t-- > 0) {
  			int n = sc.nextInt();
  			int q=sc.nextInt();
  			int w=sc.nextInt();
  			UnionFind q1=new UnionFind(n);
  			UnionFind w1=new UnionFind(n);
  			for (int i = 0; i < q; i++) {
  				q1.unionSet(sc.nextInt()-1, sc.nextInt()-1);
  			}
  			for (int i = 0; i < w; i++) {
  				w1.unionSet(sc.nextInt()-1, sc.nextInt()-1);
  			}
  			ArrayList<pair> a=new ArrayList<>();
  			for (int i = 0; i < n; i++) {
  				for (int j = i+1; j < n; j++) {
  					if(!q1.isSameSet(i, j)&&!w1.isSameSet(i, j)) {
  						q1.unionSet(i, j);
  						w1.unionSet(i, j);
  						a.add(new pair(i+1, j+1));
  					}
  				}
  			}
  			pw.println(a.size());
  			for(pair p:a)
  				pw.println(p.x+" "+p.y);
  		}
  		pw.flush();
  	}
  
  	///////////////////////////////////////////////////////////////////////////////////////////
  
  	static class tri {
  		int x, y, z;
  
  		public tri(int x, int y, int z) {
  			this.x = x;
  			this.y = y;
  			this.z = z;
  		}
  
  	}
  
  	static class pair implements Comparable<pair> {
  		int x, y;
  		boolean w, l;
  		PriorityQueue<Long> pq;
  
  		public pair(boolean a, boolean b) {
  			w = a;
  			l = b;
  		}
  
  		pair(int s, int d) {
  			x = s;
  			y = d;
  		}
  
  		@Override
  		public int compareTo(pair p) {
  			return Long.compare(x, p.x);
  		}
  
  		@Override
  		public String toString() {
  			return x + " " + y;
  
  		}
  
  	}
  
  	static long mod(long ans, int mod) {
  		return (ans % mod + mod) % mod;
  	}
  
  	static long gcd(long a, long b) {
  		if (a == 0)
  			return b;
  		return gcd(b % a, a);
  	}
  
  	static long lcm(long a, long b) {
  		return (a * b) / gcd(a, b);
  	}
  
  	public static int log(int n, int base) {
  		int ans = 0;
  		while (n + 1 > base) {
  			ans++;
  			n /= base;
  		}
  		return ans;
  	}
  
  	static long pow(long b, long e) {
  		long ans = 1;
  		while (e > 0) {
  			if ((e & 1) == 1)
  				ans = ((ans * 1l * b));
  			e >>= 1;
  			{
  
  			}
  			b = ((b * 1l * b));
  		}
  		return ans;
  	}
  
  	static long powmod(long r, long e, int mod) {
  		long ans = 1;
  		r %= mod;
  		while (e > 0) {
  			if ((e & 1) == 1)
  				ans = (int) ((ans * 1l * r) % mod);
  			e >>= 1;
  			r = (int) ((r * 1l * r) % mod);
  		}
  		return ans;
  	}
  
  	static int ceil(int a, int b) {
  		int ans = a / b;
  		return a % b == 0 ? ans : ans + 1;
  	}
  
  	static long ceil(long a, long b) {
  		long ans = a / b;
  		return a % b == 0 ? ans : ans + 1;
  	}
  
  	static HashMap<Integer, Integer> compress(int a[]) {
  		TreeSet<Integer> ts = new TreeSet<>();
  		HashMap<Integer, Integer> hm = new HashMap<>();
  		for (int x : a)
  			ts.add(x);
  		for (int x : ts) {
  			hm.put(x, hm.size() + 1);
  		}
  		return hm;
  	}
  
  	// Returns nCr % p
  	static int C[];
  
  	static int nCrModp(int n, int r, int p) {
  		if (r > n - r)
  			r = n - r;
  		if (C[r] != 0)
  			return C[r];
  		// The array C is going to store last
  		// row of pascal triangle at the end.
  		// And last entry of last row is nCr
  
  		C[0] = 1; // Top row of Pascal Triangle
  
  		// One by constructs remaining rows of Pascal
  		// Triangle from top to bottom
  		for (int i = 1; i <= n; i++) {
  
  			// Fill entries of current row using previous
  			// row values
  			for (int j = Math.min(i, r); j > 0; j--)
  
  				// nCj = (n-1)Cj + (n-1)C(j-1);
  				C[j] = (C[j] + C[j - 1]) % p;
  		}
  		return C[r];
  	}
  
  	static class Scanner {
  		StringTokenizer st;
  		BufferedReader br;
  
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
  
  		public Scanner(String file) throws Exception {
  			br = new BufferedReader(new FileReader(file));
  		}
  
  		public int[] intArr(int n) throws IOException {
  			int a[] = new int[n];
  			for (int i = 0; i < a.length; i++) {
  				a[i] = nextInt();
  			}
  			return a;
  		}
  
  		public long[] longArr(int n) throws IOException {
  			long a[] = new long[n];
  			for (int i = 0; i < a.length; i++) {
  				a[i] = nextLong();
  			}
  			return a;
  		}
  
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
  
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
  
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
  
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
  
  		public double nextDouble() throws IOException {
  			String x = next();
  			StringBuilder sb = new StringBuilder("0");
  			double res = 0, f = 1;
  			boolean dec = false, neg = false;
  			int start = 0;
  			if (x.charAt(0) == '-') {
  				neg = true;
  				start++;
  			}
  			for (int i = start; i < x.length(); i++)
  				if (x.charAt(i) == '.') {
  					res = Long.parseLong(sb.toString());
  					sb = new StringBuilder("0");
  					dec = true;
  				} else {
  					sb.append(x.charAt(i));
  					if (dec)
  						f *= 10;
  				}
  			res += Long.parseLong(sb.toString()) / f;
  			return res * (neg ? -1 : 1);
  		}
  
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
  
  	}
  
  	public static void shuffle(int[] times2) {
  		int n = times2.length;
  		for (int i = 0; i < n; i++) {
  			int r = i + (int) (Math.random() * (n - i));
  			int tmp = times2[i];
  			times2[i] = times2[r];
  			times2[r] = tmp;
  		}
  	}
  
  }