def form?(i, j, lines)
  if [lines[i+1][j], lines[i][j+1], lines[i+1][j+1]].all? {|e| e == 1}
    'A'
  end
end

def foo
  while true
    lines = []
    while gets
      break if $_ =~ /^\n/
      lines << $_.split('').map(&:to_i)
      break if lines.size == 8
    end

    next if $_ =~ /^\n/
    break if $_.nil?

    form = nil
    lines.each.with_index do |line, i|
      line.each.with_index do |char, j|
        next if char.zero?
        form = form?(i, j, lines)
        break if !form.nil?
      end
      break if !form.nil?
    end
    puts form
  end
end

foo