Subsequence Sum Queries

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

You have an array aa containing nn integers and an integer mm. You also have qq queries to answer. The ii-th query is described as a pair of integers (l_i,r_i)(l\_i, r\_i). Your task is to calculate the number of such subsequences a_j_1,a_j_2,,a_j_ka\_{j\_1}, a\_{j\_2}, \ldots, a\_{j\_k} that l_ij_1<j_2<<j_kr_il\_i \le j\_1 < j\_2 < \ldots < j\_k \le r\_i and (a_j_1+a_j_2++a_j_k)modm=0(a\_{j\_1} + a\_{j\_2} + \ldots + a\_{j\_k}) \bmod m = 0. In other words, you need to calculate the number of subsequences of subarray \[a_l_i,a_l_i+1,,a_r_i]\[a\_{l\_i}, a\_{l\_i + 1}, \ldots, a\_{r\_i}] such that the sum of elements in each subsequence is divisible by mm.

입력

The first line contains two integers nn and mm: the number of elements in aa and the modulo (1n21051 \le n \le 2 \cdot 10^5, 1m201 \le m \le 20).

The second line contains nn integers a_ia\_i: the elements of array aa (0a_i1090 \le a\_i \le 10^9).

The third line contains one integer qq: the number of queries (1q21051 \le q \le 2 \cdot 10^5).

Then qq lines follow. The ii-th of these lines contains two integers l_il\_i and r_ir\_i that describe the ii-th query (1l_ir_in1 \le l\_i \le r\_i \le n).

출력

Print qq lines. The ii-th of them must contain the answer for the ii-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+710^9 + 7.