from collections import deque
for tc in range(1,10+1):
t=int(input())
arr=deque(map(int,input().split()))
while True:
if arr[-1]==0:
break
for i in range(1,5+1):
pop=arr.popleft()
pop-=i
arr.append(pop)
if arr[-1]<=0:
arr[-1]=0
break
print(f'#{t}', end=" ")
print(*arr)