Under construction

Still being built. Things may change

Two water jugs

Interview

Time limit2sMemory limit512 MB

Summary
Given two jug capacities a and b, decide whether some sequence of fills, empties, and pours can leave exactly c liters in one jug.
Level

Medium5 of 10

Topics
Math, Number theory, Simulation
Solved
No attempts yet

Problem

You have two jugs with capacities of aa and bb liters. Water is unlimited, and you may repeat the following three operations as many times as you like.

  • Fill one jug to the top.
  • Empty one jug completely.
  • Pour water from one jug into the other, stopping when the source jug is empty or the receiving jug is full.

Write a program that decides whether you can reach a state where one of the two jugs holds exactly cc liters.

Input

The first line contains the number of test cases TT. (1≤T≤100001 \le T \le 10000)

Each of the next TT lines contains one test case, given as three integers aa, bb, cc. (1≤a,b,c≤1091 \le a, b, c \le 10^9)

Output

For each test case, print YES on its own line if exactly cc liters can be measured, and NO otherwise.

Hint

For a=5a = 5, b=3b = 3, c=4c = 4, the following steps produce 4 liters.

  • Fill aa. (a=5a = 5, b=0b = 0)
  • Pour aa into bb. (a=2a = 2, b=3b = 3)
  • Empty bb, then pour aa into bb. (a=0a = 0, b=2b = 2)
  • Fill aa. (a=5a = 5, b=2b = 2)
  • Pour aa into bb. (a=4a = 4, b=3b = 3)

Examples5

  1. Example 1

    Input
    2
    5 3 4
    3 6 4
    
    Expected output
    YES
    NO
    
  2. Example 2

    Input
    1
    1 1 1
    
    Expected output
    YES
    
  3. Example 3

    Input
    5
    4 6 6
    4 6 4
    4 6 2
    4 6 8
    4 6 10
    
    Expected output
    YES
    YES
    YES
    NO
    NO
    
  4. Example 4

    Input
    4
    5 5 5
    5 5 3
    5 5 10
    5 5 1
    
    Expected output
    YES
    NO
    NO
    NO
    
  5. Example 5

    Input
    6
    3 7 1
    3 7 2
    3 7 3
    3 7 7
    3 7 8
    7 3 5
    
    Expected output
    YES
    YES
    YES
    YES
    NO
    YES