RoAlgo PreOJI 2024 VI | operatii

This was the problem page during the contest. Access the current page here.
Time limit: 0.1s Memory limit: 16MB Input: operatii.in Output: operatii.out

Task

You are given three natural numbers, aa, bb, and kk. George, being passionate about mathematics and computer science, has invented an algorithm, and now he wants to test your computer science knowledge to find the answers he is looking for.

The algorithm described by George works as follows:

As long as aa and bb are different, print aa and bb on a new line and subtract the smaller number from the larger one.

For example, if initially a=14a = 14 and b=39b = 39, the first 55 pairs of displayed values are:

  • 14 3914 \ 39 (first pair)
  • 14 2514 \ 25 (subtract aa from bb)
  • 14 1114 \ 11 (subtract aa from bb)
  • 3 113 \ 11 (subtract bb from aa)
  • 3 83 \ 8 (subtract aa from bb)

Now, George wants to know what the values of aa and bb will be at the kk-th step.

Practically, if kk is 33, you should print 14 1114 \ 11.

Since this is too easy, he asks you to solve the problem for tt such triplets. He guarantees that the algorithm will display at least kk lines.

Input data

The first line of the input file operatii.in will contain tt, the number of triplets for which you need to solve the problem.

The following tt lines contain the triplets, each containing a b ka \ b \ k, the three numbers of the triplet.

Output data

For each triplet, print on a separate line in the file operatii.out the value of aa and the value of bb after kk steps.

Constraints and clarifications

  • 1t1 0001 \leq t \leq 1\ 000;
  • 1a,b,k1091 \leq a, b, k \leq 10^9;
  • The algorithm will display at least kk lines.
  • For tests worth 1515 points, (t=1)(t = 1) and (1a,b,k106)(1 \leq a, b, k \leq 10^6).
  • For tests worth 2525 points, (1t5)(1 \leq t \leq 5) and (1a,b,k106)(1 \leq a, b, k \leq 10^6).

Example

operatii.in

2
14 39 3
167 96 7

operatii.out

14 11
17 4

Explanation

For the first pair, the explanation is found in the statement.

For the second pair, the values of aa and bb change as follows:

  • 167 96167 \ 96
  • 71 9671 \ 96
  • 71 2571 \ 25
  • 46 2546 \ 25
  • 21 2521 \ 25
  • 21 421 \ 4
  • 17 417 \ 4

We will print 17 417 \ 4.

Log in or sign up to be able to send submissions!