spoj#CODHASH. Hashcodes and primes

Hashcodes and primes

 

There are n cards arranged in a row.The rth card from the left has rth prime number written on it on one side the other side is blank.Some cards have the blank side up and the others have the number side up.
Cards with their blank side up are known as 0-cards and cards showing the prime numbers are known as 1-cards
A hash code is generated from the set of cards in the following way:
Initial value of hashcode is 1.
All the 0-cards should be turned upside down to convert them to a 1-card in order to get the final value of hash code.
 At each step a 0-card can be turned upside down if there's at least one 1-card adjacent to it.Once the card is turned the value of the hash code is changed  according to the following equation:
new value of hashcode=(previous value of hashcode )*((number on the card)^(number of 0-cards left on the table+1))
Once all the cards on the table are 1-cards we get the final value of hash code.
Find the total number of distinct hash codes that can be generated for the given arrangement of cards.

There are n cards arranged in a row.The rth card from the left has rth prime number written on it on one side the other side is blank.Some cards have the blank side up and the others have the number side up.

Cards with their blank side up are known as 0-cards and cards showing the prime numbers are known as 1-cards

A hash code is generated from the set of cards in the following way:

Initial value of hashcode is 1.

All the 0-cards should be turned upside down to convert them to a 1-card in order to get the final value of the hash code.

At each step a 0-card can be turned upside down if there's at least one 1-card adjacent to it.Once the card is turned the value of the hash code is changed  according to the following equation:

New value of hashcode=(Previous value of hashcode )*((Number on the card)^(Number of 0-cards left on the table+1))

Once all the cards on the table are 1-cards we get the final value of hash code.

Find the total number of distinct hash codes that can be generated like this for the given arrangement of cards.

 

Input

The first line contains 0<T<=1000 (T-number of test cases)

The first line of every test case contains two integers n and m where n is the number of cards on the table and m is the number of 1-cards on the table, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of the cards that are 1-cards.

Output

For every test case print in a separate line the number of  distinct hash codes that can be generated for the given arrangement of cards modulo 1000000007 (10^9 + 7).

Example

Input:
2
3 1
1
4 2
1 4

Output: 1

</p>
2