a=%w(012345 152304 215043 310542 402351 513240).map{|l|l.chars.map &:to_i}
b=[nil,[0,3,1,4,2,5],a[0],[0,4,3,2,1,5],[0,2,4,1,3,5]]
p (n=$_.to_i)-(1..n).map{l=gets.split
m=a[l.index"Red"].map{|i|l[i]}
(b[m.index"Blue"]||b[m.index"Cyan"]).map{|i|m[i]}}.uniq.size while gets>?1