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.util.*;
  import java.io.*;
  
  public class D1 {
  
  	private static final FastScanner fs = new FastScanner();
  	private static final int MOD = 1000000007;
  
  	public static void main(String[] args) throws IOException {
  //		int cases = fs.nextInt();
  //		while (cases-- > 0)
  			solve();
  	}
  	static void solve() throws IOException {
  		int n = fs.nextInt();
  		int m1 = fs.nextInt();
  		int m2 = fs.nextInt();
  		DisjointUnionSets s1 = new DisjointUnionSets(n);
  		DisjointUnionSets s2 = new DisjointUnionSets(n);
  
  		for (int i = 0; i < m1; i++) {
  			int u = fs.nextInt();
  			int v = fs.nextInt();
  			u--; v--;
  			s1.union(u,v);
  		}
  		for (int i = 0; i < m2; i++) {
  			int u = fs.nextInt();
  			int v = fs.nextInt();
  			u--; v--;
  			s2.union(u,v);
  		}
  
  		int max = Math.min(n-m1, n-m2);
  		int r = 0;
  		StringBuilder sb = new StringBuilder();
  		for (int i = 0; i < n; i++) {
  			for (int j = i+1; j < n; j++) {
  				if (s1.find(i) == s1.find(j)
  				||  s2.find(i) == s2.find(j)) continue;
  
  				s1.union(i,j);
  				s2.union(i,j);
  				r++;
  				sb.append(i+1).append(" ").append(j+1).append("\n");
  				if (r > max) break;
  			}
  		}
  		System.out.println(r);
  		System.out.print(sb);
  	}
  
  	static class DisjointUnionSets {
  		int[] rank, parent;
  		int n;
  		public DisjointUnionSets(int n)
  		{
  			rank = new int[n];
  			parent = new int[n];
  			this.n = n;
  			for (int i = 0; i < n; i++) parent[i] = i;
  		}
  
  		int find(int i) {
  			if (parent[i] == i) return i;
  			else
  			{
  				int result = find(parent[i]);
  				parent[i] = result;
  				return result;
  			}
  		}
  
  		void union(int x, int y) {
  			int xRoot = find(x), yRoot = find(y);
  			if (xRoot == yRoot)
  				return;
  			if (rank[xRoot] < rank[yRoot])
  				parent[xRoot] = yRoot;
  			else if (rank[yRoot] < rank[xRoot])
  				parent[yRoot] = xRoot;
  			else {
  				parent[yRoot] = xRoot;
  				rank[xRoot] = rank[xRoot] + 1;
  			}
  		}
  
  		@Override
  		public String toString() {
  			return "DisjointUnionSets{" +
  					"rank=" + Arrays.toString(rank) +
  					", parent=" + Arrays.toString(parent) +
  					'}';
  		}
  	}
  
  	static class FastScanner
  	{
  		//I don't understand how this works lmao
  		private int BS = 1 << 16;
  		private char NC = (char) 0;
  		private byte[] buf = new byte[BS];
  		private int bId = 0, size = 0;
  		private char c = NC;
  		private double cnt = 1;
  		private BufferedInputStream in;
  
  		public FastScanner() {
  			in = new BufferedInputStream(System.in, BS);
  		}
  
  		public FastScanner(String s) {
  			try {
  				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  			} catch (Exception e) {
  				in = new BufferedInputStream(System.in, BS);
  			}
  		}
  
  		private char getChar() {
  			while (bId == size) {
  				try {
  					size = in.read(buf);
  				} catch (Exception e) {
  					return NC;
  				}
  				if (size == -1) return NC;
  				bId = 0;
  			}
  			return (char) buf[bId++];
  		}
  
  		public int nextInt() {
  			return (int) nextLong();
  		}
  
  		public int[] nextInts(int N) {
  			int[] res = new int[N];
  			for (int i = 0; i < N; i++) {
  				res[i] = (int) nextLong();
  			}
  			return res;
  		}
  
  		public ArrayList<Integer> nextIntsArrayList(int N) {
  			ArrayList<Integer> res = new ArrayList<>(N);
  			for (int i = 0; i < N; i++) {
  				res.add((int) nextLong());
  			}
  			return res;
  		}
  
  		public long[] nextLongs(int N) {
  			long[] res = new long[N];
  			for (int i = 0; i < N; i++) {
  				res[i] = nextLong();
  			}
  			return res;
  		}
  
  		public long nextLong() {
  			cnt = 1;
  			boolean neg = false;
  			if (c == NC) c = getChar();
  			for (; (c < '0' || c > '9'); c = getChar()) {
  				if (c == '-') neg = true;
  			}
  			long res = 0;
  			for (; c >= '0' && c <= '9'; c = getChar()) {
  				res = (res << 3) + (res << 1) + c - '0';
  				cnt *= 10;
  			}
  			return neg ? -res : res;
  		}
  
  		public double nextDouble() {
  			double cur = nextLong();
  			return c != '.' ? cur : cur + nextLong() / cnt;
  		}
  
  		public double[] nextDoubles(int N) {
  			double[] res = new double[N];
  			for (int i = 0; i < N; i++) {
  				res[i] = nextDouble();
  			}
  			return res;
  		}
  
  		public String next() {
  			StringBuilder res = new StringBuilder();
  			while (c <= 32) c = getChar();
  			while (c > 32) {
  				res.append(c);
  				c = getChar();
  			}
  			return res.toString();
  		}
  
  		public String nextLine() {
  			StringBuilder res = new StringBuilder();
  			while (c <= 32) c = getChar();
  			while (c != '\n') {
  				res.append(c);
  				c = getChar();
  			}
  			return res.toString();
  		}
  
  		public boolean hasNext() {
  			if (c > 32) return true;
  			while (true) {
  				c = getChar();
  				if (c == NC) return false;
  				else if (c > 32) return true;
  			}
  		}
  	}
  }