시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB133725752.778%

문제

동혁이는 회전을 좋아한다. 동혁이는 표에 글자를 채워넣은 다음에 이를 회전시키려고 한다.

먼저 A4용지에 R*C크기의 표를 그리고, 각 칸에 알파벳 소문자를 채워 넣는다.

그 다음 45의 배수인 K를 고른 뒤에, 그 각도만큼 시계방향으로 회전 시킨다.

이때, 동혁이가 보는 표의 모습을 출력하는 것이다. (동혁이는 마법을 부려 알파벳은 종이를 돌려도 항상 제모습 유지하도록 만들었다)

입력

첫째 줄에 R과 C가 공백으로 구분되어 주어진다. 그 다음 R개의 줄에는 동혁이가 그린 표에 적혀있는 알파벳이 주어진다. (1 ≤ R ≤ 10, 1 ≤ C ≤ 10)

마지막 줄에는 K가 주어진다. 이 수는 0보다 크거나 같고, 360보다 작거나 같은 45의 배수이다. 

출력

예제와 같은 형태로 회전 시켰을 때의 모습을 출력하면 된다. 회전 시켰을 때,  다양한 경우가 나올 수 있는데, 이럴 때는 줄의 수가 가장 작은 것을 출력하면 된다. 어떤 줄은 공백으로 시작할 수도 있고, 공백으로 끝날 수도 있다. 이때, 공백으로 시작하는 경우에는 공백을 모두 출력해야 하지만, 공백으로 끝나는 경우에는 공백을 출력하지 않고 무시한다. (모든 줄은 알파벳 소문자로 끝나야 한다.)

예제 입력 1

3 5
damir
marko
darko
45

예제 출력 1

  d
 m a
d a m
 a r i
  r k r
   k o
    o

예제 입력 2

3 5
damir
marko
darko
90

예제 출력 2

dmd
aaa
rrm
kki
oor

예제 입력 3

5 5
abcde
bcdef
cdefg
defgh
efghi
315

예제 출력 3

    e
   d f
  c e g
 b d f h
a c e g i
 b d f h
  c e g
   d f
    e
W3sicHJvYmxlbV9pZCI6IjI5NDkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiI0NVx1YjNjNCIsImRlc2NyaXB0aW9uIjoiPHA+XHViM2Q5XHVkNjAxXHVjNzc0XHViMjk0IFx1ZDY4Y1x1YzgwNFx1Yzc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