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

while true
  c = Array.new
  while true
    s = gets
    break if s.nil?
    s = s.chomp.split('').map(&:to_i)
    break if s.size == 0
    next if s.inject(:+) == 0
    c.push(s)
  end

  break if c.size == 0

  (c[0].size - 1).downto(0).each { |x| 
    s = 0 
    c.each { |r| s += r[x] }
    c.each { |r| r.delete_at(x) } if s == 0
  }

  bs.each { |k, b|
    if b.size == c.size && b[0].size == c[0].size
      r = (0..b.size - 1).map { |y| b[y] == c[y] }.uniq
      puts k if r.size == 1 && r[0]
    end 
  }
end