This page is still under construction.

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

Extraordinary Payment

Time limit1sMemory limit512 MB

Summary
Given a coin system with c1=1, decide whether the greedy algorithm always uses the minimum number of coins for every amount.
Level

Medium7 of 10

Topics
Greedy, Dynamic programming, Number theory, Math
Solved
No attempts yet

Problem

International olympiads are not only a chance for contestants to show their knowledge. They are also a chance for Mr. Malnar, who eagerly looks forward to trying the specialties of a new country. To be ready to pay for expensive dinners, he decided to convert part of his money into the currency of the country he is about to visit.

In that country all amounts are positive integers, and there are nn different coin values c1<c2<⋯<cnc_1 < c_2 < \dots < c_n used to pay amounts. Mr. Malnar's wallet can be thought of as an infinite source of money, where he has arbitrarily many coins of each value at his disposal. To pay an amount, Mr. Malnar chooses some number of coins whose sum is exactly that amount. In addition, c1=1c_1 = 1, which guarantees that every amount can be paid.

Mr. Malnar does not bother much with choosing coins, so he uses the following greedy algorithm to pay an amount: he picks the largest coin that does not exceed the amount to be paid, and repeats this procedure on the remaining amount until he has paid it in full. Since Mr. Malnar dislikes the feel of dirty money in his hands, it would be ideal for him if his greedy algorithm paid every possible amount using the minimum number of coins. He considers such a coin system extraordinary.

Mr. Malnar has so far visited tt countries, and he knows the coin system of each of them. For each country, print "DA" or "NE" depending on whether the coin system of that country is extraordinary.

Input

The first line contains the positive integer tt from the statement. (1≤t≤1001 \le t \le 100)

What follows are tt descriptions of countries, each described by two lines. The first line contains the positive integer nn, (1≤n≤10 0001 \le n \le 10\ 000) and the second line contains the positive integers 1=c1<c2<⋯<cn≤10 0001 = c_1 < c_2 < \dots < c_n \le 10\ 000 from the statement. The sum of all values of nn over all countries does not exceed 10 00010\ 000.

Output

Print tt lines, the answer for each country to the question of whether its coin system is extraordinary.

Hint

Explanation of the sample: in the third country, the amount 6 can be paid using two coins (6=3+36 = 3 + 3), but the greedy algorithm uses three coins (6=4+1+16 = 4 + 1 + 1).

Examples1

  1. Example 1

    Input
    3
    3
    1 2 5
    4
    1 3 8 13
    4
    1 3 4 10
    
    Expected output
    DA
    DA
    NE