The input contains multiple test cases. The first line of each case is an integer N, representing the size of the template is N*N (N could only be 3, 4 or 5). Next N lines describe the template. The following line contains an integer Q, which is the Scale Level of the picture. Input is ended with a case of N=0. It is guaranteed that the size of one picture will not exceed 3000*3000.
For each test case, just print the Level Q picture by using the given template.
3 # # # # # 1 3 # # # # # 3 4 OO O O O O OO 2 0
# #
#
# #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# #
# # # #
# #
#
# #
# # # #
# #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
OO OO
O OO O
O OO O
OO OO
OO OO
O O O O
O O O O
OO OO
OO OO
O O O O
O O O O
OO OO
OO OO
O OO O
O OO O
OO OO
try:
while True:
num = int(input())
if num == 0:break
result = [] #输出结果
template = [] #起初模板(不变)
for i in range(num):
template.append(input())
result.append(template[i])
sign = result[0].split()[0][0] #得到符号
zoomsNum = int(input())
for i in range(1,zoomsNum): #i为放大的倍数
replaceNum = num**i
example = [] #保存着前一个倍数的模板
blanks = " "*replaceNum #当前倍数比较起初模板空格被放大的倍数
for j in range(num): #j为起初模板对于的行
for k in range(replaceNum): #k是对应起初模板的一行中被放大倍数后的行数
if j == 0:
example.append(result[k]) #保存着前一个倍数的模板
result[k] = template[j].replace(" ",blanks) #在起初第一行模板不需要增加行数,所以只需要放大空格和符号sign就好
else:
result.append(template[j].replace(' ',blanks))
signLines = example[k] #把每一个符号位替换成上一个倍数对应的行
result[k+j*replaceNum] = result[k+j*replaceNum].replace(sign,signLines)
for i in result:
print(i)
except Exception:
pass
while True:
try:
N=int(input())
if N==0:
break
s=[]
#s为最后输出结果
sta=[]
#sta列表储存被替换字符串的模板,长度恒为N,即输入N后的N行
for n in range(N):
s.append(input())
sta.append(s[n])
for c in s[0]:#找到特殊字符
if c != ' ':
ch=c
break
Q=int(input())
lines=N**Q
for i in range(1,Q):#eg: 3(N)^3(Q) 分解为 3*9 替换
Len=N**i
'''每次替换总行数
Q=2时仅循环一次(i=1),替换N行,
Q=3时最后一次循环(i=2)替换N^2行'''
ex=[]
'''ex列表储存替换字符串的模板
eg:Q=3时最后一次(i=2),ex有9个元素
先找到sta[0]中的空格,将其替换成最后输出N^(Q-1)个空格
再将上述得到的字符串中出现的特殊字符(eg:'#')换为ex[0]
得到s[0],如此循环N^(Q-1)遍
再找到sta[1]中的空格,……以此类推
sta[N-1]……
得到s[N^Q],即N*N^(Q-1)
'''
str0=""
for h in range(Len):
str0+=' '#生成一个字符串,包含Len个空格
for j in range(N):
for k in range(Len):
if j==0:
ex.append(s[k])
s[k]=sta[j].replace(' ',str0)
else:
s.append(sta[j].replace(' ',str0))
str1=ex[k]
s[k+j*Len]=s[k+j*Len].replace(ch,str1)
for l in range(lines):#s(最后输出结果),有N^Q行
print(s[l])
except:
break