Gold Digger

0

0 votes
Very-Easy
Problem

X, a gold digger, has N mines that he wants to extract gold from, each labeled with a number from 1 to N. He has decided upon the order in which he will do his work and extract gold from these mines. The amount of gold that he is able to extract from these mines depends upon this order and is equal to the index of the order in a sorted list of all possible orders of these N mines. Your job is to find out how much gold X will be able to dig from his preferred order of mining. Since this number can be very big, you need to print its value modulo 109+7.

Input:

First line of input contains T, the number of test cases.

Each test case consists of 2 lines.

The first line of each test case contains N, the number of gold mines.

The second line of each test case contains a list of N integers between 1 and N, which represents the order in which X will mine gold.

Output:

For each test case, print the index of the given order in the sorted list of all orders modulo 109+7

Constraints:

1 <= T <= 20

1 <= N <= 105

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For 3 mines, the sorted list would be

1, 2, 3

1, 3, 2

2, 1, 3 and so on

The index of X's order in this list is 1.

Editor Image

?