eolymp
bolt
Try our new interface for solving problems
Problems

Sum on parallelepiped

Sum on parallelepiped

The three dimensional matrix of integers aijt is given, where 1in, 1jm, 1tk. For given lx, ly, lz, rx, ry, rz find

prb685

Input

First line contains the size of the matrix - n, m, k (1n, m, k100). Then given n blocks with m lines, each line contains k integers aijt (1aijt1000). The blocks are separated with empty line. Next line gives the number of queries q (1q106). Next q lines contains the queries lxi, lyi, lzi, rxi, ryi, rzi (1lxirxin, 1lyiryim, 1lzirzik).

Output

Print the answers in q separate lines.

Time limit 1 second
Memory limit 122.17 MiB
Input example #1
2 3 5
1 2 3 4 5
5 4 3 2 1
2 3 1 5 4

1 2 3 4 5
5 4 3 2 1
2 3 1 5 4
5
1 1 1 1 2 2
1 1 1 2 2 2
1 2 3 2 3 4
1 3 4 2 3 5
1 2 4 2 2 5
Output example #1
12
24
22
18
6
Author В.Гольдштейн
Source Зимние сборы в Харькове 2010 День 2