#P1017H. The Films
The Films
Description
In "The Man in the High Castle" world, there are different film endings.
Abendsen owns a storage and a shelf. At first, he has ordered films on the shelf. In the -th month he will do:
- Empty the storage.
- Put films into the storage, films for each ending.
- He will think about a question: if he puts all the films from the shelf into the storage, then randomly picks films (from all the films in the storage) and rearranges them on the shelf, what is the probability that sequence of endings in on the shelf will not be changed? Notice, he just thinks about this question, so the shelf will not actually be changed.
Answer all Abendsen's questions.
Let the probability be fraction . Let's say that the total number of ways to take films from the storage for -th month is , so is always an integer. Print for each month .
is a prime number and it is equal to .
It is guaranteed that there will be only no more than different values.
The first line contains three integers , , and (, ) — the number of films on the shelf initially, the number of endings, and the number of months.
The second line contains integers () — the ending of the -th film on the shelf.
Each of the next lines contains three integers , , and () — the -th query.
It is guaranteed that there will be only no more than different values.
Print the answer for each question in a separate line.
Input
The first line contains three integers , , and (, ) — the number of films on the shelf initially, the number of endings, and the number of months.
The second line contains integers () — the ending of the -th film on the shelf.
Each of the next lines contains three integers , , and () — the -th query.
It is guaranteed that there will be only no more than different values.
Output
Print the answer for each question in a separate line.
Note
In the first sample in the second query, after adding films into the storage, the storage will look like this: .
There are total ways of choosing the films so that will not be changed, for example, and are such ways.
There are total ways of choosing the films, so you're asked to print .