def rotate arr
    rotated_arr = Array.new(arr.size){Array.new(arr[0].size)}
    for i in (0 ... arr.size)
        for j in (0 ... arr[0].size)
            rotated_arr[i][j] = arr[arr.size - 1 - j][i]
        end
    end
    rotated_arr
end

pattern = []
8.times{pattern << gets.chomp.split("")}

p = pattern
for i in 1..3
    puts 90 * i
    p = rotate(p)
    p.each{|line| puts line.join}
end