Distance
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述


Gromah and LZR have entered the fourth level. There is a blank cube with size  hanging on the wall.

Gromah soon finds a list beside the cube, there are  instructions in the list and each instruction is in one of the following two formats:

1. , meaning to add a tag on position  in the cube
2. , meaning to determine the minimum Manhattan Distance to the given position  among all tagged positions

Manhattan Distance between two positions (x_1, y_1, z_1), (x_2, y_2, z_2) is defined as .

LZR also finds a note board saying that the password of this level is the sequence made up of all results of the instructions in format 2.

Please help them get all results of the instructions in format 2.

输入描述:

The first line contains four positive integers , denoting the sizes in three dimensions of the cube and the number of instructions.

Following  lines each contains four positive integers , where  means to add a tag on  while  means to make a query on .



It is guaranteed that the first instruction is in format 1 and that no position will be tagged more than once.


输出描述:

For each instruction in format 2, output the answer in one line.
示例1

输入

复制
3 3 3 4
1 1 1 1
2 2 3 3
1 3 1 1
2 3 3 2

输出

复制
5
3

说明

For the first query, there is only one tagged position (1,1,1)_{} currently, so the answer is |1-2| + |1-3| + |1-3| = 5_{}.

For the second query, (3,1,1)_{} is the nearest tagged position, so the answer is |3-3| + |1-3| + |1-2| = 3_{}.