Under construction

Still being built. Things may change

Dice

Interview

Time limit2sMemory limit1024 MB

Summary
Given n dice with f faces and a modifier m, decide whether a reported total S is reachable by checking if S minus m lies between n and n times f.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Khodislav is playing a tabletop role-playing game. He has finally chosen his weapons to deal with a monster and casts the crushing strike. To do this, he rolls dice, adds up the numbers on their faces, and announces the sum to the game master.

A group of identical dice rolls is defined by three integers nn, ff, and mm. Here nn is the number of dice, ff is the number of faces on each die, and mm is the modifier. Each face shows every number from 11 to ff, any face can come up, and all rolls are independent. For example, if n=3n = 3, f=8f = 8, and m=5m = 5, the player rolls three eight-sided dice, adds the results, and then adds 55. This is usually written as 3d8+53d8 + 5.

The game master wants to check whether the sum Khodislav reported can actually be obtained from the roll.

Input

The first line contains a single integer BB (1≤B≤1051 \le B \le 10^5), the number of strikes cast by Khodislav. Each of the following BB lines describes one strike with four integers: the reported sum SS, followed by nn, ff, and mm. The constraints are 1≤S≤3001 \le S \le 300, 1≤n≤101 \le n \le 10, 2≤f≤202 \le f \le 20, and 0≤m≤100 \le m \le 10.

Output

For each strike, in the same order as the input, print YES if the reported sum is achievable, and NO otherwise. Print each answer on its own line.

Examples1

  1. Example 1

    Input
    5
    3 1 6 0
    1 1 8 1
    16 1 12 3
    1 2 4 0
    42 3 20 1
    
    Expected output
    YES
    NO
    NO
    NO
    YES