route = {"a" => ["x", "y"], "x" => ["s", "z"], "y" => ["x", "s"], "z" => ["w", "b"], "w" => ["b", "y"], "b" => ["y", "x"], "s" => ["s", "s"]}
while line = gets
    line = line.chomp
    break if line == "#"
    city = "a"
    line.split("").map(&:to_i).each{|x| city = route[city][x]}
    puts city == "b" ? "Yes" : "No"
end

