This page is still under construction.

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

Vepar

Time limit1.5sMemory limit512 MB

Summary
For each test case, decide whether the product of all integers from c to d is divisible by the product of all integers from a to b.
Level

Medium7 of 10

Topics
Number theory, Math, Combinatorics, Prefix sum
Solved
No attempts yet

Problem

Two intervals of positive integers {a,a+1,…,b}\{a, a + 1, \ldots, b\} and {c,c+1,…,d}\{c, c + 1, \ldots, d\} are given. Determine whether the product c⋅(c+1)⋯dc \cdot (c+1) \cdots d is divisible by the product a⋅(a+1)⋯ba \cdot (a+1) \cdots b.

Input

The first line contains a single integer tt, the number of independent test cases. (1≤t≤101 \le t \le 10)

Each of the following tt lines contains four positive integers ai,bi,ci,dia_i, b_i, c_i, d_i. (1≤ai≤bi≤1071 \le a_i \le b_i \le 10^7, 1≤ci≤di≤1071 \le c_i \le d_i \le 10^7)

Output

Output tt lines in total. For the ii-th test case, output DA if ai⋅(ai+1)⋯bia_i \cdot (a_i + 1) \cdots b_i divides ci⋅(ci+1)⋯dic_i \cdot (c_i + 1) \cdots d_i, and output NE otherwise.

Hint

We have 9⋅10=909 \cdot 10 = 90 and 3⋅4⋅5⋅6=3603 \cdot 4 \cdot 5 \cdot 6 = 360. The answer is DA because 90 divides 360.

We calculate 2⋅3⋅4⋅5=1202 \cdot 3 \cdot 4 \cdot 5 = 120, which does not divide 7⋅8⋅9=5047 \cdot 8 \cdot 9 = 504. Thus the second answer is NE.

Examples2

  1. Example 1

    Input
    2
    9 10 3 6
    2 5 7 9
    
    Expected output
    DA
    NE
    
  2. Example 2

    Input
    6
    1 2 3 4
    1 4 2 3
    2 3 1 4
    1 3 2 4
    19 22 55 57
    55 57 19 22
    
    Expected output
    DA
    NE
    DA
    DA
    DA
    DA