gets
$<.map(&:split).combination(2).map{|e|c,d=e
f=->a{a.map{|i|d[i]}.rotate.map.with_index{|v,i|d[a[i]]=v}}
(0..23).map{|i|f[[1,2,4,3]]
d==c&&(puts :No)^exit
i%4<1&&f[i%8<4?[0,4,5,1]:[0,2,5,3]]}}
puts:Yes