Backup

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

There are many different backup strategies. The easiest to understand are the differential and incremental backups.

With incremental backup, we create a copy of the data which were changed from the moment of the last backup: for instance, after a full backup on Sunday, on Monday we copy the data that were changed during Monday; the same goes for Tuesday, etc. With such strategy, the volume of data copied is relatively small, but it may require a lot of files to restore the data. For instance, to restore data on Friday, we would need backup copies from Sunday (full backup), Monday, Tuesday, Wednesday and Thursday.

With differential backup, we regularly create a full copy --- for instance, every Sunday. Next, on each day of the week we make a copy of all data modified after the last full backup: a Monday copy on Monday, a Monday and Tuesday copy on Tuesday, etc. The total volume of the backed up data is relatively large, but you only need two files to restore data: the last differential and the last full backup.

Dump(1), a popular backup freeware, operates with the concept of backup level, which can perform incremental or differential backup as well as more complex strategies, which cannot be reduced to the two former methods. The idea of backup levels as such is pretty simple: when we make an NN level backup, we copy all files modified from the moment of the last backup with the level lower than NN.  If there are no preceding lower-level backups, we make a complete backup copy of all data.

Write a program to figure out which backup files should be used for recovery based on the backup schedule.

입력

The first line of the input file contains the number MM -- the total number of tests in the file (0<M100,0000 < M \le 100\\,000).

Each following line of the input file consists of eight space-separated integers. The first seven numbers are schedule of backups, i.e. the levels of backup N_iN\_i, which are performed on the corresponding days of the week ii: on Sunday, Monday, Tuesday, etc. (0N_i90 \le N\_i \le 9). It is guaranteed that the zero-level backup is performed on Sunday, i.e. the first number is zero.

The eighth number is the day dd when data must be recovered (0d60 \le d \le 6). Note that 00 is Sunday and 66 is Saturday.

출력

For each line of the output file, print a sequence of numbers d_jd\_j corresponding to the days when the backup copies necessary for recovery were made (0d_j60 \le d\_j \le 6). Note that the earliest copy is always recovered first, followed by a later copy, hence the following must hold true: d_j<d_j+1d\_j < d\_{j+1} and N_d_j<N_d_j+1N\_{d\_j} < N\_{d\_{j+1}}. Moreover, the recovery always ends with the latest copy, so the last number in the line must equal dd.