#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(a) cout<< #a << " : " << a <<endl;
#define bug2(a, b) cout<< #a << " : " << a << " " << #b << " : " << b << endl;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int even[N], odd[N];
ll pw[N];
void solve(int cs){
int n, q;
cin >> n >> q;
for(int i = 1;i <= n;i++){
int x;
cin >> x;
if(x & 1){
odd[i] = odd[i - 1] + 1;
even[i] = even[i - 1];
}
else{
even[i] = even[i - 1] + 1;
odd[i] = odd[i - 1];
}
}
while(q--){
int t, l, r;
cin >> t >> l >> r;
ll od = odd[r] - odd[l - 1];
ll ev = even[r] - even[l - 1];
if(t == 1){
if(od == 0) cout << 0 << '\n';
else{
ll ans = pw[od - 1] * pw[ev];
ans %= mod;
cout << ans << '\n';
}
}
else{
ll ans = (od == 0 ? 1 : pw[od - 1]) * pw[ev];
ans %= mod;
ans = ((ans - 1) + mod) % mod;
cout << ans << '\n';
}
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cout.tie(0);
int tc = 1;
// cin >> tc;
pw[0] = 1;
for(int i = 1;i < N;i++){
pw[i] = pw[i - 1] * 2;
pw[i] %= mod;
}
for(int cs = 1; cs <= tc; cs++){
solve(cs);
}
}