There is a planet, in a yet undiscovered part of the universe, with a country inhabited solely by mathematicians. In this country, there are a total of N mathematicians, and the interesting fact is that each mathematician lives in their own city. Is it also interesting that no two cities are connected with a road, because mathematicians can communicate online or by reviewing academic papers. Naturally, the cities are labeled with numbers from 1 to $$$N$$$.
Life was perfect until one mathematician decided to write an academic paper on their smartphone. The smartphone auto-corrected the word "self-evident" to "Pictionary" and the paper was published as such. Soon after, the entire country discovered pictionary and wanted to meet up and play, so construction work on roads between cities began shortly.
The road construction will last a total of $$$M$$$ days, according to the following schedule: on the first day, construction is done on roads between all pairs of cities that have $$$M$$$ as their greatest common divisor. On the second day, construction is done on roads between all pairs of cities that have $$$M-1$$$ as their greatest common divisor, and so on until the $$$M$$$th day when construction is done on roads between all pairs of cities that are co-prime. More formally, on the $$$i$$$th day, construction is done on roads between cities $$$a$$$ and $$$b$$$ if $$$\gcd(a, b) = M - i + 1$$$.
Since the mathematicians are busy with construction work, they've asked you to help them determine the minimal number of days before a given pair of mathematicians can play pictionary together.
The first line of input contains three positive integers N, M and Q ($$$1 \leq N$$$, $$$Q \leq 10^5$$$, $$$1 \leq M \leq N$$$), the number of cities, the number of days it takes to build the roads, and the number of queries.
Each of the following Q lines contains two distinct positive integers A and B ($$$1 \leq A, B \leq N$$$) that denote the cities of the mathematicians who want to find out the minimal number of days before they can play pictionary together.
The $$$i$$$th line must contain the minimal number of days before the mathematicians from the $$$i$$$th query can play pictionary together.
8 3 3 2 5 3 6 4 8
3 1 2
25 6 1 20 9
4
9999 2222 2 1025 2405 3154 8949
1980 2160
On the first day, road (3, 6) is built. Therefore the answer to the second query is 1. On the second day, roads (2, 4), (2, 6), (2, 8), (4, 6) and (6, 8) are built. Cities 4 and 8 are now connected (it is possible to get from the first to the second using city 6). On the third day, roads between relatively prime cities are built, so cities 2 and 5 are connected.
On the second day, road (20, 15) is built, whereas on the fourth day, road (15, 9) is built. After the fourth day, cities 20 and 9 are connected via city 15.
You have been given the coordinates of $$$N$$$ points in three-dimensional space—namely, $$$P_1, P_2, \dots, P_N$$$. Initially, these points are distributed into $$$N$$$ singleton sets, one for each point. You have been asked to execute $$$Q$$$ operations involving these sets.
Operations may be of three distinct types:
The first line contains a single integer $$$N$$$, indicating the number of points which follow. Each of the next $$$N$$$ lines contain three integers $$$x_i$$$, $$$y_i$$$ and $$$z_i$$$, representing the coordinates of the $$$i$$$th point.
The next line contains an integer $$$Q$$$, indicating the number of queries that should be answered. Each of the next $$$Q$$$ lines represents a query, and has one of the following three formats:
Limites:
For each Type 3 query, you should print its answer in a single line.
5 1 5 0 2 4 0 3 3 0 4 2 0 5 1 0 7 3 1 2 1 1 4 3 1 2 1 2 5 3 1 2 2 3 1 2
2 4 8 4
4 -10 -10 0 -10 10 0 10 -10 0 10 10 0 6 3 2 4 1 1 2 3 2 4 3 4 3 3 1 3 3 1 4
20 40 20 40 40