public static void main(String[] args) throws IOException {
		long inicio = System.currentTimeMillis();
		StringBuilder out = new StringBuilder();
		BufferedReader in;
		File archivo = new File("entrada");
		if (archivo.exists())
			in = new BufferedReader(new FileReader(archivo));
		else
			in = new BufferedReader(new InputStreamReader(System.in));

		String line = "";
		int k[];
		int q = 0, a, b;

		while ((line = in.readLine()) != null) {
			int n = Integer.parseInt(line.split(" ")[0]);
			int m = Integer.parseInt(line.split(" ")[1]);
			UF uf = new UF();
			uf.MakeSet(n);
			for (int i = 0; i < m; i++) {
				k = readInts(in.readLine());
				q = k[0];
				if (q == 1) {
					a = k[1] - 1 + n;
					b = k[2] - 1 + n;
					if (!uf.sameComponent(a, b)) {
						uf.UnionbyRank(a, b);
					}
				} else if (q == 2) {
					a = k[1] - 1 + n;
					b = k[2] - 1 + n;
					if (!uf.sameComponent(a, b)) {
						uf.separate(a, b);
					}
				} else {
					a = k[1] - 1 + n;
					out.append(uf.elements[uf.Find(a)] + " " + (uf.sum[uf.Find(a)])
							+ "\n");
				}
			}
		}
		System.out.print(out);
		if (archivo.exists())
			System.out.println("Tiempo transcurrido : "
					+ (System.currentTimeMillis() - inicio) + " milisegundos.");
	}