You are given a grid, where each lattice point is labelled by a (not necessarily distinct) non-negative integer. There are two types of operations:
- Change the label of a lattice point to another non-negative integer.
- Find the shortest path between two lattice points.
Here the length of a path is defined as the sum of labels of all lattice points the path passes through, and two lattice points are adjacent if they have Manhattan distance 1 (i.e. if ).
Input Specification
The first line of input will contain a single integer, .
The next 6 lines will contain integers each, where the th integer in the th row is the label of .
The following line will contain a single integer, , the number of operations.
The operations will be one of the following:
1 x y c
: The label of is changed to , where , , .2 x1 y1 x2 y2
: Output the length of the shortest path between and , as defined above, where , .
Output Specification
For each type 2 operation, output the length of the shortest path between and on a new line.
Sample Input
5
0 0 1 0 0
0 1 0 1 0
0 2 0 1 0
0 1 1 1 0
0 0 0 0 0
1 1 1 1 1
5
2 1 2 1 4
1 1 1 10000
2 1 2 1 4
1 2 3 10000
2 1 2 3 3
Sample Output
0
1
2
Constraints
Case | ||
---|---|---|
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 |
Comments