#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<utility>
#define ll long long
#define nl '\n'
using namespace std;
const ll N=1e9+7;
ll ncr(ll n, ll r) {
if (r > n) return 0;
if (r == 0 || n == r) return 1;
ll mul = 1;
for (int i = 0; i < r; i++) {
mul = mul * (n - i) / (i + 1);
}
return mul;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,q;
cin>>n>>q;
ll a[n];
ll pre[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i == 0) {
pre[i] = (a[i] % 2 == 1) ? 1 : 0;
} else {
pre[i] = pre[i - 1] + (a[i] % 2 == 1 ? 1 : 0);
}
}
while(q-- ){
ll x,y,z;
cin>>x>>y>>z;
y--;z--;
ll odd=pre[z]-pre[y];
if(a[x]%2==1){
odd++;
}
ll even=z-y+1-odd;
if(x==0){
ll combination_odd=0;
for(int i=2;i<= odd ;i+=2){
combination_odd+=ncr(odd,i)%N;
}
ll combination_even=0;
for(int i=1;i<=even ;i++){
combination_even+=ncr(even,i)%N;
}
ll ans=(combination_even+combination_odd+combination_even*combination_odd)%N;
cout<<ans<<nl;
}
else{
ll combination_odd=0;
for(int i=1;i<= odd ;i+=2){
combination_odd+=ncr(odd,i)%N;
}
ll combination_even=0;
for(int i=1;i<=even ;i++){
combination_even+=ncr(even,i)%N;
}
ll ans=combination_odd+combination_even*combination_odd;
cout<<ans%N<<nl;
}
}
}