Number of Obtainable Amounts

No attempts yetTime limit1sMemory limit128 MB

Problem

Hektor really enjoys programming problems about making change, or more generally about forming sums of money from a given set of denominations. Some time ago he noticed that many such problems become easy when every denomination is a multiple of the one before it.

Solve the following problem: given the values of consecutive denominations and how many banknotes of each you hold, how many distinct amounts can you form?

We only consider sets of denominations in which each denomination is a multiple of the previous one.

An amount "can be formed" if and only if some subset of the banknotes you hold has values that sum to exactly that amount.

Because the number of achievable amounts can be very large, print it modulo 109+710^9 + 7.

Input

The first line contains the number of test cases ZZ (1Z101 \le Z \le 10). Each test case then follows.

The first line of a test case contains a natural number NN (1N10001 \le N \le 1000), the number of denominations.

The second line contains NN natural numbers; the ii-th of them, xix_i (1xi1091 \le x_i \le 10^9), is the number of banknotes of the ii-th denomination.

The third line contains N1N-1 natural numbers; the ii-th of them, did_i (1di1091 \le d_i \le 10^9), means that the value of the (i+1)(i+1)-th denomination equals di×d_i \times (the value of the ii-th denomination). The first denomination has value 11.

Output

For each test case, print the number of distinct achievable amounts modulo 109+710^9 + 7, one per line.