CF2102A.Dinner Time

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Dinner Time

Given four integers nn, mm, pp, and qq, determine whether there exists an integer array a1,a2,,ana_1, a_2, \ldots, a_n (elements may be negative) satisfying the following conditions:

  • The sum of all elements in the array is equal to mm: $$a_1 + a_2 + \ldots + a_n = m$$
  • The sum of everyppconsecutive elements is equal toqq:$$a_i + a_{i + 1} + \ldots + a_{i + p - 1} = q,\qquad\text{ for all }1\le i\le n-p+1$$

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first and only line of each test case contains four integers nn, mm, pp, and qq (1pn1001 \le p \le n \le 100, 1q,m1001 \le q, m \le 100) — the length of the array, the sum of elements, the length of a segment, and the sum of a segment, respectively.

Output

For each test case, output "YES" (without quotes) if there exists an array satisfying the above conditions, and "NO" (without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yES", "yes", and "Yes" will all be recognized as valid responses).

Note

In the first test case, an example of an array satisfying the condition is [1,0,1][1, 0, 1]. This is because:

  • a1+a2+a3=1+0+1=2=ma_1+a_2+a_3 = 1+0+1 = 2 = m
  • a1+a2=1+0=1=qa_1+a_2=1+0=1=q
  • a2+a3=0+1=1=qa_2+a_3=0+1=1=q

In the second test case, the only array satisfying the condition is [1][1].

In the third test case, an example of an array satisfying the condition is [2,5,2,5,2][-2, 5, -2, 5, -2].

In the fourth test case, it can be proven that there is no array satisfying the condition.

Samples

5
3 2 2 1
1 1 1 1
5 4 2 3
10 7 5 2
4 4 1 3
YES
YES
YES
NO
NO

在线编程 IDE

建议全屏模式获得最佳体验