XOR love
Difficulty: Hard

Devendra loves the XOR operation very much which is denoted by $\wedge$ sign in most of the programming languages. He has a list $A$ of $N$ numbers and he wants to know the answers of $M$ queries. Each query will be denoted by three numbers i.e. $K,P,R$ .

For query $K,P \text{ and } R$, he has to print the value of the $KPRsum$ which can be described as given below. As the value of the $KPRsum$ can be large. So, print it modulus $(10^9 + 7)$.

$$ KPRsum = \sum_{i=P}^{R-1} \sum_{j=i+1}^{R} (K \oplus (A[i] \oplus A[j]) )$$

**Input Format**  
The first line contains an integer $N$, i.e., the number of the elements in the list. List is numbered from $1$ to $N$.  
Next line will contain $N$ space seperated integers.  
Third line will contain a number $M$ i.e. number of queries followed by $M$ lines each containing  integers $K,P \& R$.

**Output Format**  
Print $M$ lines, $i^{th}$ line will be answer of $i^{th}$ query. **Answer will be 0 in case of P=R.**

**Constraints**  
$1 \le N \le 10^5$  
$1 \le A[i] \le 10^6$  
$1 \le M \le 10^5$  
$0 \le K \le 10^6$  
$1 \le P \le R \le N$

**Sample Input**  

	3
    1 2 3
    2
    1 1 3
    2 1 3

    
**Sample Output**  

	5
    4

**Explanation**

For first query, it will will be $$(1 \oplus( 1 \oplus 2) ) + (1 \oplus( 1 \oplus 3) ) + (1 \oplus( 2 \oplus 3) )  =  5 $$

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
###C++  
```cpp  
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<stdlib.h>
#include<string.h>
#include<utility>
#include<assert.h>
using namespace std;
typedef long long int ll;
int A[100001][31];
int main()
{
    ll answer=0,ones,zeros,o,z;
    int N,x,pow[31],y,k,M;
    pow[0]=1;
    for(int i=1;i<31;i++) pow[i]=pow[i-1]<<1;
    scanf("%d",&N);
    assert(N<=100000 && N>=1);
    for(int i=0;i<31;i++) A[0][i]=0;
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&x);
        assert(x<=1000000 && x>=1);
        for(int j=0;j<31;j++) A[i][j] = A[i-1][j]+((x&pow[j])?1:0);
    }
    scanf("%d",&M);
    assert(M<=10000);
    while(M--)
    {
        answer=0;
        scanf("%d",&k);
        assert(k>=1 && k<=1000000);
        x=0;
        y=N;
        for(int i=0;i<31;i++){
        o=A[y][i]-A[x][i];
        z = (y-x) - o;
        ones = z*o;
        zeros = (z*(z-1) + o*(o-1))/2;
        if((k&pow[i])==0)
        answer = (answer + (ll)pow[i]*ones);
        else
        answer = (answer + (ll)pow[i]*zeros);
        }
        printf("%lld\n",answer%(1000000007));
        
    }
    return 0;
 }
```