import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Solution_SWEA_1225_암호생성기 {
public static void main(String[] args) throws Exception {
StringBuilder sb = new StringBuilder("");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int testCase = 1; testCase <= 10; testCase++) {
int count = 1;
int t = Integer.parseInt(br.readLine());
Queue<Integer> queue = new LinkedList<>();
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < 8; i++) {
queue.offer(Integer.parseInt(st.nextToken()));
}
while (true) {
int num = queue.poll();
if (num - count <= 0) {
queue.offer(0);
break;
}
queue.offer(num - count);
if (count == 5) {
count = 0;
}
count++;
}
sb.append("#").append(t).append(" ");
for (int i = 0; i < 8; i++) {
sb.append(queue.poll()).append(" ");
}
sb.append("\n");
}
System.out.print(sb);
}
}