This page is still under construction.

Parts of this page are still being built. What you see may change.

The Stones Game

Time limit1sMemory limit128 MB

Summary
Given N stones and M players in cyclic order with forced removals, decide if player X has a strategy that always takes the last stone.
Level

Medium7 of 10

Topics
Game theory, Math
Solved
No attempts yet

Problem

The stones game has simple rules and it is very old.

The game starts with NN stones and MM players. The players are numbered from 11 to MM. Player 11 takes the first turn, then player 22, and so on up to player MM. After player MM finishes a turn, player 11 goes again, and the game repeats this order until it ends.

Each turn consists of the following two steps.

  1. The player whose turn it is gets a chance to remove one stone. If the player decides to remove a stone, exactly one stone leaves the pile in this step.
  2. This step happens regardless of the decision made in step 1. If this is not the first turn and the player of the previous turn decided not to remove a stone in step 1, then the current player must remove one stone in this step. If the player of the previous turn did remove a stone in step 1, then the current player must not remove a stone in this step.

So a player removes 0, 1 or 2 stones during a single turn, depending on the rules above. The player who removes the last stone wins the game.

You are given the number of stones, the number of players, and one player number. Decide whether that player has a strategy that always wins, whatever the other players do on their turns.

Input

Your program is tested on one or more test cases. The first line of the input has a single integer TT, the number of test cases (1≤T≤1001 \le T \le 100). Each of the next TT lines describes one test case and holds three integers separated by a single space, NN, MM, XX (1≤N,M≤1091 \le N, M \le 10^9, 1≤X≤M1 \le X \le M), the number of stones, the number of players, and the player number.

Output

For each test case, print a single word on its own line. Print YES if player XX has a strategy that always wins regardless of what the other players do, and NO otherwise.

Examples2

  1. Example 1

    Input
    2
    2 2 2
    2 2 1
    
    Expected output
    YES
    NO
    
  2. Example 2

    Input
    3
    10 5 5
    10 5 1
    1 3 1
    
    Expected output
    YES
    NO
    YES