CF BUDDY
← Problems·

1612D · X-Magic Pair

1600 · math, number theory

Problem: You are given a pair of integers (a,b)(a, b) and an integer xx.

You can change the pair in two different ways:

  • set (assign) a:=aba := |a - b|;
  • set (assign) b:=abb := |a - b|,

The pair (a,b)(a, b) is called xx-magic if xx is obtainable either as aa or as bb using only the given operations (i.e. the pair (a,b)(a, b) is xx-magic if a=xa = x or b=xb = x after some number of operations applied). You can apply the operations any number of times (even zero).

Your task is to find out if the pair (a,b)(a, b) is xx-magic or not.

You have to answer tt independent test cases.

Input Format: The first line of the input contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. The next tt lines describe test cases.

The only line of the test case contains three integers aa, bb and xx (1a,b,x10181 \le a, b, x \le 10^{18}).

Output Format: For the ii-th test case, print YES if the corresponding pair (a,b)(a, b) is xx-magic and NO otherwise.

Sample Cases

Case 1

Input

8
6 9 3
15 38 7
18 8 8
30 30 30
40 50 90
24 28 20
365 216 52
537037812705867558 338887693834423551 3199921013340

Output

YES
YES
YES
YES
NO
YES
YES
YES

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback