LCM^k

Given three integers N,M,K and array of integers a1,a2,...,an.
Find the value of LCM(a1k,a2k,...,ank) mod M, where LCM means Least Common Multiple.

Input

The first line of the input contains a single integer T denoting the number of test cases(1 ≤ T ≤ 10). 
The description of T test cases follows.
First line contains three positive integers N, M, K(1 ≤ N ≤ 3 * 105, 1 ≤ M, K ≤ 109).
The second line contains N space-separated integers a1,a2,...,an.(1 ≤ ai ≤ 106,1 ≤ i  N).

Output
For each test case print the value of LCM(a1k,a2k,...,ank) mod M.

SAMPLE INPUT
 
1
5 20 3
17 2 9 4 12
SAMPLE OUTPUT
 
8
Explanation

In the test LCM(173,23,93,43,123) = 229220928, 229220928 mod 20 = 8.

Note:- Time Extended Problem Occur

Comments

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Setting Up PostgreSQL Logical Replication with Docker Compose

Regex 101: An Introduction to Regular Expressions for Developers