创建于 2026/07/18 · 更新于 2026/07/18
Maru the golden retriever is passionate about ice skating—he lives for the thrill of gliding at breakneck speed across the rink. Unfortunately, his enthusiasm far exceeds his skill. Maru's control is... questionable at best (possibly because he normally uses all four of his legs). More often than not, he ends up crashing into obstacles or launching himself spectacularly off the edge of the rink.

The rink can be described as a grid of rows and columns, and we use to denote the cell on the -th row and the -th column. Thus is the upper-left corner, and is the bottom-right corner. Initially, there are obstacles on the rink where the -th obstacle is on the cell , and all the remaining cells are empty.
If Maru is currently at , he has two options to move:
Notice that, regardless of how far Maru moves in one option, it is considered one move.
Maru doesn't have much energy left, because his humans refused to give him a second breakfast; he wants to know the minimum number of moves to reach a "stable position". A "stable position" is a position where he cannot move to another position, no matter how he chooses to move next.
You need to support operations, each of which belongs to one of the following two types:
The first line contains four integers , representing the size of the rink, the number of obstacles initially, and the number of operations.
In the following lines, each line contains two integers , representing the position of the -th obstacle. It's guaranteed that the positions of obstacles are pairwise distinct.
In the following lines, each line contains three integers , representing the -th operation.
For each query, output a single line with a single integer, representing the answer.
8 9 6 3
3 4
5 4
7 3
5 7
1 8
6 2
1 3 2
2 6 4
1 3 2
2
The image below shows one possible answer to each query in the example.
