import java.io.*;
import java.util.*;

public class birthday_md {
	static final int DAYS = 31;
	static final int MONTHS = 12;

	void run() {
		int[][] countMonths = new int[3][MONTHS];
		int[][] countDays = new int[3][DAYS];
		boolean[][][] possible = new boolean[3][MONTHS][DAYS];
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			int day = in.nextInt() - 1;
			int month = in.nextInt() - 1;
			possible[0][month][day] = true;
		}
		for (int t = 0; t < 3; t++) {
			for (int i = 0; i < MONTHS; i++) {
				for (int j = 0; j < DAYS; j++) {
					if (possible[t][i][j]) {
						countMonths[t][i]++;
						countDays[t][j]++;
					}
				}
			}
			for (int i = 0; i < MONTHS; i++) {
				for (int j = 0; j < DAYS; j++) {
					if (t == 0) {
						possible[1][i][j] = possible[0][i][j] && (countDays[0][j] >= 2);
						for (int k = 0; k < MONTHS; k++) {
							if (!possible[0][k][j]) {
								continue;
							}
							if (countMonths[0][k] == 1) {
								possible[1][i][j] = false;
							}
						}
					} else if (t == 1) {
						possible[2][i][j] = possible[1][i][j] &&
								(countMonths[0][i] >= 2) && (countMonths[1][i] == 1);
					} else {
						if (possible[2][i][j] && (countDays[2][j] == 1)) {
							out.println((j + 1) + " " + (i + 1));
						}
					}
				}
			}
		}
	}

	static Scanner in;
	static PrintWriter out;
	
	public static void main(String[] args) throws IOException {
		String fileName = birthday_md.class.getSimpleName().replaceFirst("_.*", "").toLowerCase();
		String inputFileName = fileName + ".in";
		String outputFileName = fileName + ".out";
		
		Locale.setDefault(Locale.US);
		in = new Scanner(new File(inputFileName));
		out = new PrintWriter(outputFileName);
		new birthday_md().run();
		in.close();
		out.close();
	}
}
