CF2193E Product Queries

Description

Today, Sabyrzhan was called to the board with an array $ a $ of length $ n $ and was assigned an officer's task — to answer $ n $ questions. In the $ i $ -th question, it is required to determine the minimum number of elements from the array that need to be selected from the board (it is allowed to use the same element multiple times) so that their product is exactly equal to $ i $ , or to report that it is impossible to achieve such a product. Note that at least one element must be selected.

Input Format

Each test consists of several test cases. The first line contains one integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $ n $ ( $ 1 \le n \le 3 \cdot 10 ^ 5 $ ). The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le n $ ). It is guaranteed that the sum of the values of $ n $ across all test cases does not exceed $ 3 \cdot 10 ^ 5 $ .

Output Format

For the $ i $ -th question, output one integer — the minimum number of elements from the array required to obtain a product equal to $ i $ , or $ −1 $ if it is impossible to achieve such a product.

Explanation/Hint

Consider the first test case. The products can be obtained as follows: - $ 1 $ cannot be obtained. - $ 2 $ can be obtained by selecting $ a_2 $ . - $ 3 $ can be obtained by selecting $ a_1 $ . - $ 4 $ can be obtained by selecting $ a_2 $ twice. - $ 5 $ cannot be obtained. - $ 6 $ can be obtained by selecting $ a_7 $ . - $ 7 $ can be obtained by selecting $ a_5 $ . - $ 8 $ can be obtained by selecting $ a_2 $ three times.