Division Expression

Time limit1sMemory limit128 MB

Summary
Given a left-to-right division expression of n positive integers, decide if some parenthesization yields an integer value, which reduces to checking if x1 times the product of x3..xn is divisible by x2.
Level

Medium4 of 10

Topics
Math, Number theory, Greedy
Solved
No attempts yet

Problem

A division expression is an arithmetic expression of the form

x1/x2/x3/⋯/xkx_1 / x_2 / x_3 / \cdots / x_k

where each xix_i is a positive integer for 1≤i≤k1 \le i \le k. A division expression is evaluated from left to right. For instance, the value of

1/2/1/21/2/1/2

is 1/41/4.

You may insert parentheses into the expression to change its value. For example, the value of

(1/2)/(1/2)(1/2)/(1/2)

is 11.

You are given a division expression EE. Decide whether it is possible to insert parentheses into EE to obtain an expression E′E' whose value is an integer.

Write a program that, for each data set in a sequence of data sets, reads an expression EE, determines whether some placement of parentheses makes its value an integer, and reports the result.

Input

The first line contains one positive integer dd (d≤5d \le 5), the number of data sets. The data sets follow.

The first line of each data set contains an integer nn (2≤n≤100002 \le n \le 10000), the number of integers in the expression. Each of the next nn lines contains exactly one positive integer no greater than 1 000 000 0001\,000\,000\,000; the ii-th of these is xix_i, the ii-th integer in the expression.

Output

For each data set, print on its own line YES if the expression can be parenthesized so that its value is an integer, and NO otherwise.

Examples3

  1. Example 1

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

    Input
    1
    2
    6
    3
    
    Expected output
    YES
    
  3. Example 3

    Input
    1
    2
    3
    6
    
    Expected output
    NO