LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

Ideal Elections

HardProblem #34
Time LimitMemoryInputOutput
2 s64 MBstdinstdout

Work one prime at a time, and remember the answer can be enormous - keep it modulo 10^9 + 7.

Elections for the title of "Best Number" are being held in Saransk. There are n people at the polling station, and the i-th of them carries a number ai​.

When a person steps into the booth, they do not vote for their own number - they vote for a candidate that is a divisor of it. So the i-th person picks some pi​ that divides ai​ (this can be 1, or ai​ itself, or anything in between).

After everyone has voted we are left with an array of votes [p1​,p2​,…,pn​]. The organizer calls the vote ideal when the least common multiple of all the votes equals their product:

lcm(p1​,p2​,…,pn​)=p1​⋅p2​⋅…⋅pn​

Here lcm is the least common multiple - the smallest number divisible by every pi​.

Count how many different ideal arrays of votes are possible. Two arrays are different if they differ in at least one position. The count can be enormous, so print it modulo 109+7.

Input

The first line contains the number of test cases t.

Each test case takes two lines. The first line has a single integer n - the number of voters. The second line has n integers a1​,a2​,…,an​ - the numbers they carry.

The sum of n over all test cases does not exceed 105.

Output

For each test case print one line: the number of ideal vote arrays, modulo 109+7.

Example

Input
4
4
2 3 1 4
2
2 4
6
3 9 1 6 4 5
7
1 2 3 67 13 8 8
Output
8
4
40
64

In the first test we have 8 valid arrays - for example everyone voting 1, or the fourth person voting 4 while the rest vote 1, etc..

Constraints

1≤t≤104
1≤n≤105
1≤ai​≤5⋅105
The sum of n over all test cases does not exceed 105.


This problem was adapted from Elections in Saransk (easy version), problem F1 of Codeforces Round 1103 (Div. 3).

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit