def lscan; gets.split.map(&:to_i); end h = {} h[[2,8]] = 1 h[[3,9]] = 2 h[[7,9]] = 3 cnt = 10 gets.to_i.times do a,b,c,d = lscan abort h.to_s if h[[c,d]] i = h[[a,b]] i ||= (cnt += 1) 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