def lscan; gets.split.map(&:to_i); end h = {} h[[2,8]] = 1 h[[3,9]] = 2 h[[7,9]] = 3 gets.to_i.times do a,b,c,d = lscan i = h[[a,b]] h[[a,b]] = 0 h[[c,d]] = i end if h[[5,8]] == 1 && h[[4,8]] == 2 && h[[6,8]] == 3 puts 'YES' else puts 'NO' end