ADABASET - Ada and Database


Ada the Ladybug has inserted all data from her TODO-list into the database. The database is represented as multidimensional structure with direct indexing. Your task is simple - read the database and tell Ada the data on given indices!

Input

There will be multiple test-cases.

The first line of each test-case contains n integers 1≤ Di ≤ 105 , indicating the size of each dimense. n will be between 2 and 10. Their product won't exceed 106

Each of following D1×D2×...×Dn-1 lines contains Dn integers (where Dn is size of last dimension), all between 0 and 1018.

Last line of each test-case contains 0 to 5 queries. Each query consists of n integers A1, ... ,An, where 1 ≤ Ai ≤ Di (note that array is one-indexed).

Input file will have at most 2*106 integers. There won't be any other lines than those described above.

NOTE: If you are not confident about what number is on index [A1][A2]...[An], imagine input as D1 blocks of D2 blocks of D3 blocks of ... of Dn integers.

Output

For each query, output integer on indices [A1][A2]...[An] on a single line. After each test-case, output line with as many hashes ('#'), as the number of test-case (beginning with 1)

Example Input

2 2
1 2
3 4
1 1 1 2 2 1 2 2
2 2 2
10 9
8 7
6 5
2 1
2 2 2
1 2 6
1 2 3 4 5 6
6 5 4 3 2 1
1 1 1 1 2 1

Example Output

1
2
3
4
#
1
##
1
6
###


Added by:Morass
Date:2017-02-16
Time limit:4s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All