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 abort "?#{[c,d]}" if h[[c,d]] i = h[[a,b]] h[[a,b]] = nil h[[c,d]] = i end if h[[5,8]] == 1 && h[[4,8]] == 2 && h[[6,8]] == 3 puts 'YES' else puts 'NO' end