You will be given a description of several different calendars. You will have to convert the date of one calendar to the other one. If there are p months in a calendar then the calendar is described by a positive integer p followed by p positive integers. These p integers denote the number of days in each month. The months are identified by integers 1, 2, ..., p. You do not need to worry about leap years etc as there are no such things associated with these calendars.
Please note that for this problem days, months and years are 1-indexed and these calendars start from the same day (The very first day of all calendars 1-1-1 is the same day).
Input
First line of the input file contains a positive integer NC (1 ≤ NC ≤ 200) denoting the number of calendar descriptions to follow. Each of the next NC lines describe a Calendar. These calendars are identified as Calendar 1, 2, ..., NC respectively.
The description of each calendar is given in a single line. The line starts with an integer p (0 < p ≤ 20) which denotes the number of months in the calendar followed by p positive integers m1, m2, ..., mp, here mi denotes the number of days the i-th month has. None of these p integers exceed the value 50.
The next line contains an integer q (1 ≤ q ≤ 1000) which denotes the number of queries. Each of the next q lines contain a single query.
Each query has five integers: cal1 (1 ≤ cal1 ≤ NC), cal2 (1 ≤ cal2 ≤ NC), day, month and year (1 ≤ year ≤ 5000). Here day, month, year denotes a date in cal1 and the task is to convert it to the corresponding date in cal2. You can assume that no invalid date will be given as input.
Output
For each query your program should produce one line of output. Each output contains the query number and three integers d2, m2, y2 which denotes the day, month and year of the date when converted to cal2. See the samples for details.
Sample
Sample Input | Sample Output |
---|---|
2 3 10 20 30 4 20 30 10 20 2 1 2 18 2 2 2 1 17 4 1 | Query 1: 8 1 2 Query 2: 7 2 2 |