#nt702. Power Tower
Power Tower
Power Tower
Problem Source
Codeforces Round #454 (Div. 1) D
Problem Description
You are given numbers and queries. For each query, given an interval , you must compute .
Input Format
The first line contains two integers (, ).
The next line contains integers ().
The next line contains an integer (). The following lines each contain two integers ().
Output Format
Output lines, each containing one number: the answer for that query.
Sample Input
6 1000000000
1 2 2 3 3 3
8
1 1
1 6
2 2
2 3
2 4
4 4
4 5
4 6
Sample Output
1
1
2
4
256
3
27
597484987