408413: GYM103115 G cocktail with snake

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. cocktail with snaketime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

The favorite game of Mr.Cocktail is dota2. Serpentine walking is a useful skill to dodge the enemy's attack. Serpentine walking refers to the path of movement that keeps swing direction like a snake. Suppose the map is a n*m two-dimensional plane. Mr.Cocktail at the point (1,1) in initial.

He will first go to the right to the end, that is, point (n,1). Then turn and go one step upwards to point (n,2). Go to the left again to the end, that is, point (1,2),. Then go one step up, and go to the right again to the end.

The picture above is the action line when n=3 and m=4.

Now the map size is n*m . The number of steps k of Cocktail's movement are known. Find the Manhattan distance from the position after k steps to the starting point according to the rule.

Manhattan distance Definition: The distance between two points measured along axes at right angles. In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 - x2| + |y1 - y2|.

Input

The first line contains a positive integer T, which represents the number of groups to be tested. $$$(1 \leq T \leq 10^4)$$$

Next contains T lines, each row contains three integers $$$n, m, k(1 \leq n, m \leq 10^{18}, 0 \leq k \leq min(n*m-1, 10^{18}))$$$

Output

For each test data, output a line of one coordinate to represent the answer. (A positive integer separated by two spaces represents the x and y coordinates respectively)

ExampleInput
5
3 3 1
3 3 2
3 3 3
3 3 4
3 3 5
Output
1
2
3
2
1

加入题单

上一题 下一题 算法标签: