405020: GYM101741 J Subsequence Sum Queries
Description
You have an array a containing n integers and an integer m. You also have q queries to answer. The i-th query is described as a pair of integers (li, ri). Your task is to calculate the number of such subsequences aj1, aj2, ..., ajk that li ≤ j1 < j2 < ... < jk ≤ ri and . In other words, you need to calculate the number of subsequences of subarray [ali, ali + 1, ..., ari] such that the sum of elements in each subsequence is divisible by m.
InputThe first line contains two integers n and m: the number of elements in a and the modulo (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 20).
The second line contains n integers ai: the elements of array a (0 ≤ ai ≤ 109).
The third line contains one integer q: the number of queries (1 ≤ q ≤ 2·105).
Then q lines follow. The i-th of these lines contains two integers li and ri that describe the i-th query (1 ≤ li ≤ ri ≤ n).
OutputPrint q lines. The i-th of them must contain the answer for the i-th query. Queries are indexed in the order they are given in the input. Since the answers can be very large, print them modulo 109 + 7.
ExampleInput4 3Output
5 1 3 2
4
1 2
1 3
1 4
2 4
2
4
6
4