public static void main(String args[])
	{
		In in = new In(args[0]);
		int N = in.readInt();
		UnionFindWQU qf = new UnionFindWQU(N);
		while (!in.isEmpty())
		{
			int p = in.readInt();
			int q = in.readInt();

			if (qf.connected(p, q))
				continue;

			qf.union(p, q);
			System.out.println(p + " " + q);
		}
		System.out.println(qf.componentCount() + " components");
	}