Yash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays around with more complex things such as Fibonacci-ish potentials. 

Fibonacci-ish potential of an array *a*<sub class="lower-index">*i*</sub> is computed as follows: 
 1.  Remove all elements *j* if there exists *i* &lt; *j* such that *a*<sub class="lower-index">*i*</sub> = *a*<sub class="lower-index">*j*</sub>. 1.  Sort the remaining elements in ascending order, i.e. *a*<sub class="lower-index">1</sub> &lt; *a*<sub class="lower-index">2</sub> &lt; ... &lt; *a*<sub class="lower-index">*n*</sub>. 1.  Compute the potential as *P*(*a*) = *a*<sub class="lower-index">1</sub>·*F*<sub class="lower-index">1</sub> + *a*<sub class="lower-index">2</sub>·*F*<sub class="lower-index">2</sub> + ... + *a*<sub class="lower-index">*n*</sub>·*F*<sub class="lower-index">*n*</sub>, where *F*<sub class="lower-index">*i*</sub> is the *i*-th Fibonacci number (see notes for clarification). 
You are given an array *a*<sub class="lower-index">*i*</sub> of length *n* and *q* ranges from *l*<sub class="lower-index">*j*</sub> to *r*<sub class="lower-index">*j*</sub>. For each range *j* you have to compute the Fibonacci-ish potential of the array *b*<sub class="lower-index">*i*</sub>, composed using all elements of *a*<sub class="lower-index">*i*</sub> from *l*<sub class="lower-index">*j*</sub> to *r*<sub class="lower-index">*j*</sub> inclusive. Find these potentials modulo *m*.
The first line of the input contains integers of *n* and *m* (1 ≤ *n*, *m* ≤ 30 000) — the length of the initial array and the modulo, respectively.

The next line contains *n* integers *a*<sub class="lower-index">*i*</sub> (0 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>) — elements of the array.

Then follow the number of ranges *q* (1 ≤ *q* ≤ 30 000).

Last *q* lines contain pairs of indices *l*<sub class="lower-index">*i*</sub> and *r*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ *n*) — ranges to compute Fibonacci-ish potentials.
For the purpose of this problem define Fibonacci numbers as follows: 
 1.  *F*<sub class="lower-index">1</sub> = *F*<sub class="lower-index">2</sub> = 1. 1.  *F*<sub class="lower-index">*n*</sub> = *F*<sub class="lower-index">*n* - 1</sub> + *F*<sub class="lower-index">*n* - 2</sub> for each *n* &gt; 2. 
In the first query, the subarray [1,2,1] can be formed using the minimal set {1,2}. Thus, the potential of this subarray is 1*1+2*1=3.
print("_RANDOM_GUESS_1690486006.322107")# 1690486006.3221252