Move a point by one unit in any of the four directions so that it stays within a given distance from a target point.
Problem
You are given a point and a target point . In one move, you may shift the point by exactly 1 unit in one of the four cardinal directions: up, down, left, or right.
Find a move that results in a new position that is still within distance from the target point, where distance is measured using the Euclidean metric. In other words, after the move, the squared distance to the target should not exceed .
If there are multiple valid moves, any one of them is acceptable.
Notes
- The starting point itself may or may not already satisfy the condition.
- You only need to output one valid new position.
- It is guaranteed in the original problem that a solution exists.
Input Format
- The first line contains an integer — the number of test cases.
- Each test case contains four integers: , , , and , followed by the allowed distance .
- The exact original input format may vary slightly by platform, but the task is to choose a valid adjacent point based on the given coordinates and distance.
Output Format
For each test case, output two integers — the coordinates of any position reachable in one move from that satisfies the distance constraint.
Constraints
- is small to moderate in the original contest setting.
- Coordinates and distance fit in standard 32-bit signed integers.
- A valid answer is always guaranteed.
- A move must change exactly one coordinate by .
Example 1
Input
1 0 0 1 1 2
Output
1 0
Explanation
Moving from to gives squared distance , which is within .
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.