import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[][] x = new int[n][4]; for (int i = 0; i < n; i++) { String[] sa = br.readLine().split(" "); for (int j = 0; j < 4; j++) { x[i][j] = Integer.parseInt(sa[j]); } } br.close(); boolean[] flg = new boolean[3]; int[][] a = new int[3][]; a[0] = new int[]{2, 8}; a[1] = new int[]{3, 9}; a[2] = new int[]{7, 9}; for (int i = 0; i < n; i++) { if (!flg[0] && x[i][2] == 2 && x[i][3] == 8) { System.out.println("NO"); return; } if (!flg[1] && x[i][2] == 3 && x[i][3] == 9) { System.out.println("NO"); return; } if (!flg[2] && x[i][2] == 7 && x[i][3] == 9) { System.out.println("NO"); return; } if (x[i][0] == 2 && x[i][1] == 8) { flg[0] = true; } if (x[i][0] == 3 && x[i][1] == 9) { flg[1] = true; } if (x[i][0] == 7 && x[i][1] == 9) { flg[2] = true; } for (int j = 0; j < a.length; j++) { if (x[i][0] == a[j][0] && x[i][1] == a[j][1]) { a[j][0] = x[i][2]; a[j][1] = x[i][3]; } } } if (a[0][0] == 5 && a[0][1] == 8 && a[1][0] == 4 && a[1][1] == 8 && a[2][0] == 6 && a[2][1] == 8) { System.out.println("YES"); } else { System.out.println("NO"); } } }