graphics = {
  'A' => [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
  'B' => [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
  'C' => [1, 1, 1, 1],
  'D' => [1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1],
  'E' => [1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1],
  'F' => [1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1],
  'G' => [1, 1, 0, 0, 0, 0, 0, 1, 1]
}

grids = []

while line = gets
  if line.chomp == ''
    graphics.each do |name, graphic|
      if grids.flatten.join =~ /#{graphic.join}/
        puts name
        break
      end
    end
    grids = []
  else
    grids << line.chomp.split('').map(&:to_i)
  end
end