#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define m 1000000007
									//nestedcode

int power(int x, unsigned int y)
{
    int res = 1;      // Initialize result

    x = x % m;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % m;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % m;
    }
    return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,q,i,l,r,p,z,f,g;
	string s;
	cin>>n>>q;
	ll a[n+5],d[n+5]={0};
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='0'){
			a[i]=1;
		}else{
			a[i]=0;
		}
	//	cout<<a[i]<<endl;
	}
	for(i=0;i<s.length();i++){
		if(i!=0){
			d[i]=d[i-1]+a[i];
		//	cout<<d[i]<<endl;
		}else{
			d[i]=a[i];
		}
	}

	for(i=0;i<q;i++){
		cin>>l>>r;;
		g=r-l+1;
		l--;
		if(l==0) l=1;
		r--;
		p=d[r]-d[l-1];

	//	cout<<p<<" ";
		f=power(2,g);
		//cout<<l<<" ";
		z=pow(2,p);
		cout<<f-z<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define m 1000000007
									//nestedcode

int power(ll x,ll y)
{
    int res = 1;      // Initialize result

    x = x % m;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % m;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % m;
    }
    return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,q,i,l,r,p,z,f,g;
	string s;
	cin>>n>>q;
	ll a[n+5],d[n+5]={0};
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='0'){
			a[i]=1;
		}else{
			a[i]=0;
		}
	//	cout<<a[i]<<endl;
	}
	for(i=0;i<s.length();i++){
		if(i!=0){
			d[i]=d[i-1]+a[i];
		//	cout<<d[i]<<endl;
		}else{
			d[i]=a[i];
		}
	}

	for(i=0;i<q;i++){
		cin>>l>>r;;
		g=r-l+1;
		l--;
		if(l==0) l=1;
		r--;
		p=d[r]-d[l-1];

	//	cout<<p<<" ";
		f=power(2,g);
		//cout<<l<<" ";
		z=power(2,p);
		cout<<(f%m-z%m+ m)%m<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define m 1000000007
									//nestedcode

ll power(ll x,ll y)
{
    ll res = 1;      // Initialize result

    x = x % m;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % m;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % m;
    }
    return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,q,i,l,r,p,z,f,g;
	string s;
	cin>>n>>q;
	ll a[n+5],d[n+5]={0};
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='0'){
			a[i]=1;
		}else{
			a[i]=0;
		}
	//	cout<<a[i]<<endl;
	}
	for(i=0;i<s.length();i++){
		if(i!=0){
			d[i]=d[i-1]+a[i];
		//	cout<<d[i]<<endl;
		}else{
			d[i]=a[i];
		}
	}

	for(i=0;i<q;i++){
		cin>>l>>r;;
		g=r-l+1;
		l--;
		if(l==0) l=1;
		r--;
		p=d[r]-d[l-1];

	//	cout<<p<<" ";
		f=power(2,g);
		//cout<<l<<" ";
		z=power(2,p);
		cout<<((f%m)-(z%m)+ m)%m<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
# define ll long long int
									//nestedcode

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,q,i,l,r,p,z,f,g;
	string s;
	cin>>n>>q;
	ll a[n+5],d[n+5]={0};
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='0'){
			a[i]=1;
		}else{
			a[i]=0;
		}
	//	cout<<a[i]<<endl;
	}
	for(i=0;i<s.length();i++){
		if(i!=0){
			d[i]=d[i-1]+a[i];
		//	cout<<d[i]<<endl;
		}else{
			d[i]=a[i];
		}
	}
	for(i=0;i<q;i++){
		cin>>l>>r;;
		g=r-l+1;
		l--;
		if(l==0) l=1;
		r--;
		p=d[r]-d[l-1];

		//cout<<p<<" ";
		f=pow(2,g);
		//cout<<l<<" ";
		z=pow(2,p);
		cout<<f-z<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define m 1000000007
									//nestedcode

ll power(ll x,ll y)
{
    ll res = 1;      // Initialize result

    x = x % m;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % m;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % m;
    }
    return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,q,i,l,r,p,z,f,g;
	string s;
	cin>>n>>q;
	ll a[n+5],d[n+5]={0};
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='0'){
			a[i]=1;
		}else{
			a[i]=0;
		}
	//	cout<<a[i]<<endl;
	}
	for(i=0;i<s.length();i++){
		if(i!=0){
			d[i]=d[i-1]+a[i];
		//	cout<<d[i]<<endl;
		}else{
			d[i]=a[i];
		}
	}

	for(i=0;i<q;i++){
		cin>>l>>r;;
		g=r-l+1;

		if(l==1){
		    p=d[r-1];
		}else
		p=d[r-1]-d[l-2];

	//	cout<<p<<" ";
		f=power(2,g);
	//	cout<<g<<" "<<p<<" ";
		z=power(2,p);
		cout<<((f%m)-(z%m)+ m)%m<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define m 1000000007
									//nestedcode

int power(int x, unsigned int y)
{
    int res = 1;      // Initialize result

    x = x % m;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % m;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % m;
    }
    return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,q,i,l,r,p,z,f,g;
	string s;
	cin>>n>>q;
	ll a[n+5],d[n+5]={0};
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='0'){
			a[i]=1;
		}else{
			a[i]=0;
		}
	//	cout<<a[i]<<endl;
	}
	for(i=0;i<s.length();i++){
		if(i!=0){
			d[i]=d[i-1]+a[i];
		//	cout<<d[i]<<endl;
		}else{
			d[i]=a[i];
		}
	}
	for(i=0;i<q;i++){
		cin>>l>>r;;
		g=r-l+1;
		l--;
		if(l==0) l=1;
		r--;
		p=d[r]-d[l-1];

		//cout<<p<<" ";
		f=power(2,g);
		//cout<<l<<" ";
		z=power(2,p);
		cout<<f-z<<endl;
	}

}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const ll mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   while(y){
      if(y%2)ans=ans*x%mod;
      y/=2;
      x=x*x%mod;
   }
   //cout<<ans<<endl;
   return ans%mod;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
       // printf("%c",str[i]);
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        ll tmp = sub[r]-sub[l-1];
        ll ans = pow_mod(2LL,(ll)(r-l+1) )-pow_mod(2LL,r-l+1-tmp);
        if(ans<0)ans+=mod;
        printf("%lld\n",ans );
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const int mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   while(y){
      if(y%2)ans=ans*x%mod;
      y/=2;
      x=x*x%mod;
   }
   //cout<<ans<<endl;
   return ans%mod;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        printf("%lld\n",(pow_mod(2,r-l+1)-pow_mod(2,r-l+1-sub[r]+sub[l-1])+mod)%mod );
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const ll mod = 1e9+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   while(y){
      if(y%2)ans=(ans*x)%mod;
      y/=2;
      x=(x*x)%mod;
   }
   return ans;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
       // printf("%c",str[i]);
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        ll tmp = sub[r]-sub[l-1];
        ll ans = pow_mod(2LL,(ll)(r-l+1) )-pow_mod(2LL,r-l+1-tmp);
        if(ans<0)ans+=mod;
        printf("%lld\n",ans );
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const ll mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   while(y){
      if(y%2)ans=ans*x%mod;
      y/=2;
      x=x*x%mod;
   }
   //cout<<ans<<endl;
   return ans%mod;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        printf("%lld\n",(pow_mod(2,r-l+1)-pow_mod(2,r-l+1-sub[r]+sub[l-1])+(ll)2*mod)%mod );
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const ll mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   while(y){
      if(y%2)ans=(ans*x)%mod;
      y/=2;
      x=(x*x)%mod;
   }
   return ans;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
       // printf("%c",str[i]);
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        ll tmp = sub[r]-sub[l-1];
        ll ans = pow_mod(2LL,(ll)(r-l+1) )-pow_mod(2LL,r-l+1-tmp);
        if(ans<0)ans+=mod;
        printf("%lld\n",ans );
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const int mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   //cout<<x<<endl;
   while(y){
      if(y%2)ans=(ans%mod*x%mod)%mod;
      y/=2;
      x=x*x%mod;
   }
   //cout<<ans<<endl;
   return ans%mod;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        printf("%lld\n",pow_mod(2,r-l+1)-pow_mod(2,r-l+1-sub[r]+sub[l-1]));
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const ll mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   while(y){
      if(y%2)ans=ans*x%mod;
      y/=2;
      x=x*x%mod;
   }
   //cout<<ans<<endl;
   return ans%mod;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
       // printf("%c",str[i]);
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        ll ans = pow_mod(2,r-l+1)-pow_mod(2,r-l+1-sub[r]+sub[l-1]);
        if(ans<0)ans+=mod;
        printf("%lld\n",ans );
    }
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include<time.h>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
typedef long long ll;
const ll inf = 1e13;
const int maxn = 1e6 + 3;
void read(ll &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;

}
const int mod = 109+7;
char str[maxn];
int sub[maxn];

ll pow_mod(ll x,ll y){
   ll ans = 1;
   //cout<<x<<endl;
   while(y){
      if(y%2)ans=(ans%mod*x%mod)%mod;
      y/=2;
      x=x*x%mod;
   }
   //cout<<ans<<endl;
   return ans%mod;
}
int main(){
    int n,m;
    cin>>n>>m>>(str+1);
    for(int i=1;i<=n;i++){
        if(str[i]=='1'){
            sub[i]=sub[i-1]+1;
        }
        else {
            sub[i]=sub[i-1];
        }
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        printf("%lld\n",(pow_mod(2,r-l+1)-pow_mod(2,r-l+1-sub[r]+sub[l-1])+mod)%mod );
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int pwr[N];
int psum[N];

void preprocessing() {
  pwr[0] = 1;
  for (int i=1;i<N;i++) {
    pwr[i] = (pwr[i-1] * 2) % MOD;
  }
}

int main () {
  int n, a;
  preprocessing();
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=1;i<=n;i++) {
    psum[i] = psum[i-1] + (haha[i-1] - '0');
  }
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    unsigned long total = 0;
    unsigned long ones = 0,zeros = 0;
    ones = psum[c] - psum[b-1];
    zeros = c-b - ones + 1;

    total = (1ll * (pwr[ones]-1)*(pwr[zeros]))%MOD;
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main () {
  int n, a;
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    long total = 0;
    long pgkt = 1, duaPgkt = 1;
    for (int j=b-1;j<=c-1;j++) {
      if (haha[j] == '1') {
        pgkt *= 2;
      } else {
        duaPgkt *= 2;
      }
    }
    total = (pgkt-1) + (pgkt-1)*(duaPgkt/2);
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main () {
  int n, a;
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    unsigned long total = 0;
    unsigned long pgkt = 1, duaPgkt = 1;
    for (int j=b-1;j<=c-1;j++) {
      if (haha[j] == '1') {
        pgkt *= 2%1000000007;
      } else {
        duaPgkt *= 2%1000000007;
      }
    }
    if (duaPgkt == 0) duaPgkt = 1;
    total = ((pgkt-1)*(duaPgkt))%1000000007;
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main () {
  int n, a;
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    string kata = haha.substr(b-1, c-b+1);
    long total = 0;
    long pgkt = 1, duaPgkt = 1;
    for (int j=0;j<kata.length();j++) {
      if (kata[j] == '1') {
        pgkt *= 2;
      } else {
        duaPgkt *= 2;
      }
    }
    total = (pgkt-1) + (pgkt-1)*(duaPgkt/2);
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main () {
  int n, a;
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    unsigned long total = 0;
    unsigned long pgkt = 1, duaPgkt = 0;
    for (int j=b-1;j<=c-1;j++) {
      if (haha[j] == '1') {
        pgkt *= 2%1000000007;
      } else {
        if (duaPgkt == 0) duaPgkt = 1;
        duaPgkt *= 2%1000000007;
      }
    }
    if (duaPgkt == 0) duaPgkt = 1;
    total = ((pgkt-1)*(duaPgkt))%1000000007;
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main () {
  int n, a;
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    unsigned long total = 0;
    unsigned long pgkt = 1, duaPgkt = 1;
    for (int j=b-1;j<=c-1;j++) {
      if (haha[j] == '1') {
        pgkt *= 2;
      } else {
        duaPgkt *= 2;
      }
    }
    total = ((pgkt-1)*(1+duaPgkt/2))%1000000007;
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int pwr[N];
int psum[N];

void preprocessing() {
  pwr[0] = 1;
  for (int i=1;i<N;i++) {
    pwr[i] = (pwr[i-1] * 2) % MOD;
  }
}

int main () {
  int n, a;
  preprocessing();
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=1;i<=n;i++) {
    psum[i] = psum[i-1] + (haha[i-1] - '0');
  }
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    unsigned long total = 0;
    unsigned long ones = 0,zeros = 0;
    ones = psum[c] - psum[b-1];
    zeros = c-b - ones + 1;

    total = ((pwr[ones]-1)*(pwr[zeros]))%MOD;
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main () {
  int n, a;
  cin >> n >> a;
  string haha;
  getline(cin, haha);
  getline(cin, haha);
  int b,c;
  for (int i=0;i<a;i++) {
    cin >> b >> c;
    unsigned long total = 0;
    unsigned long pgkt = 1, duaPgkt = 1;
    for (int j=b-1;j<=c-1;j++) {
      if (haha[j] == '1') {
        pgkt *= 2%1000000007;
      } else {
        duaPgkt *= 2%1000000007;
      }
    }
    total = ((pgkt-1)*(1+duaPgkt/2))%1000000007;
    cout << total << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
inline void Routine() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
istream &operator >> (istream &in, vector<T> &v) {
    for (auto &i : v) {
        in >> i;
    }
    return in;
}

template<class T>
ostream &operator << (ostream &out, const vector<T> &v) {
    for (auto &i : v) {
        out << i << ' ';
    }
    return out;
}
const long long MOD=1e9+7;
int ct[1000]={0};
int main() {
    Routine();

    int n,q;
    cin >> n >> q;
    string s;
    cin  >> s;
    ll kol[n+1];
    kol[0]=0;
    for(int i=1;i<=n;i++){

        kol[i]=kol[i-1];
        if (s[i-1]=='1'){
            kol[i]++;
        }

    }
    ll cnt[kol[n]+1];
    ll j=1;
    cnt[0]=0;
    for(int i=0;i<kol[n];i++){
        cnt[i+1]=(j+cnt[i])%MOD;
        j+=j;
        j%=MOD;

    }
    ll dv[100001];
    dv[0]=1;
    for(int u=1;u<100001;u++){
        dv[u]=(dv[u-1]*2)%MOD;
    }

    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        int k=y-x+1;
        ll ans=0,ansi=0;
        ansi=kol[y]-kol[x-1];

        ans=(ans+cnt[ansi])%MOD;
        ll p=k-ansi;

        ans=(ans*(((dv[p+1]-1)%MOD)/2+1))%MOD;

        cout << ans << endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
inline void Routine() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
istream &operator >> (istream &in, vector<T> &v) {
    for (auto &i : v) {
        in >> i;
    }
    return in;
}

template<class T>
ostream &operator << (ostream &out, const vector<T> &v) {
    for (auto &i : v) {
        out << i << ' ';
    }
    return out;
}
const long long MOD=1e9+7;
int ct[1000]={0};
int main() {
    Routine();

    int n,q;
    cin >> n >> q;
    string s;
    cin  >> s;
    ll kol[n+1];
    kol[0]=0;
    for(int i=1;i<=n;i++){

        kol[i]=kol[i-1];
        if (s[i-1]=='1'){
            kol[i]++;
        }

    }
    ll cnt[kol[n]+1];
    ll j=1;
    cnt[0]=0;
    for(int i=0;i<kol[n];i++){
        cnt[i+1]=(j+cnt[i])%MOD;
        j+=j;
        j%=MOD;

    }

    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        int k=y-x+1;
        ll ans=0,ansi=0;
        ansi=kol[y]-kol[x-1];

        ans=(ans+cnt[ansi])%MOD;
        ll p=k-ansi;

        ans=(ans*(((p+1)*p%MOD)/2+1))%MOD;

        cout << ans << endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
inline void Routine() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
istream &operator >> (istream &in, vector<T> &v) {
    for (auto &i : v) {
        in >> i;
    }
    return in;
}

template<class T>
ostream &operator << (ostream &out, const vector<T> &v) {
    for (auto &i : v) {
        out << i << ' ';
    }
    return out;
}
const long long MOD=1e9+7;
int ct[1000]={0};
int main() {
    Routine();

    int n,q;
    cin >> n >> q;
    string s;
    cin  >> s;
    ll kol[n+1];
    kol[0]=0;
    for(int i=1;i<=n;i++){

        kol[i]=kol[i-1];
        if (s[i-1]=='1'){
            kol[i]++;
        }

    }

    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        int k=y-x+1;
        ll ans=0,ansi=0;
        ansi=kol[y]-kol[x-1];

        ll s=1;
        for(int l=1;l<=ansi;l++){

            ans+=s;
            ans=ans%MOD;
            s=s+s;
            s=s%MOD;

        }
        s--;
        for(int ii=0;ii<k-ansi;ii++){

            ans+=s;
            ans=ans%MOD;
            s=s+s;
            s=s%MOD;

        }

        cout << ans << endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
inline void Routine() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
istream &operator >> (istream &in, vector<T> &v) {
    for (auto &i : v) {
        in >> i;
    }
    return in;
}

template<class T>
ostream &operator << (ostream &out, const vector<T> &v) {
    for (auto &i : v) {
        out << i << ' ';
    }
    return out;
}
const long long MOD=1e9+7;
int ct[1000]={0};
int main() {
    Routine();

    int n,q;
    cin >> n >> q;
    string s;
    cin  >> s;
    ll kol[n+1];
    kol[0]=0;
    for(int i=1;i<=n;i++){

        kol[i]=kol[i-1];
        if (s[i-1]=='1'){
            kol[i]++;
        }

    }
    ll cnt[kol[n]+1];
    ll j=1;
    cnt[0]=0;
    for(int i=0;i<kol[n];i++){
        cnt[i+1]=(j+cnt[i])%MOD;
        j+=j;
        j%=MOD;

    }
    ll dv[100001];
    dv[0]=1;
    for(int u=1;u<100001;u++){
        dv[u]=(dv[u-1]*2)%MOD;
    }

    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        int k=y-x+1;
        ll ans=0,ansi=0;
        ansi=kol[y]-kol[x-1];

        ans=(ans+cnt[ansi])%MOD;
        ll p=k-ansi;

        ans=(ans*(((dv[p]-1)%MOD)+1))%MOD;

        cout << ans << endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
inline void Routine() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
istream &operator >> (istream &in, vector<T> &v) {
    for (auto &i : v) {
        in >> i;
    }
    return in;
}

template<class T>
ostream &operator << (ostream &out, const vector<T> &v) {
    for (auto &i : v) {
        out << i << ' ';
    }
    return out;
}
const long long MOD=1e9+7;
int ct[1000]={0};
int main() {
    Routine();

    int n,q;
    cin >> n >> q;
    string s;
    cin  >> s;
    ll kol[n+1];
    kol[0]=0;
    for(int i=1;i<=n;i++){

        kol[i]=kol[i-1];
        if (s[i-1]=='1'){
            kol[i]++;
        }

    }
    ll cnt[kol[n]+1];
    ll j=1;
    cnt[0]=0;
    for(int i=0;i<kol[n];i++){
        cnt[i+1]=(j+cnt[i])%MOD;
        j+=j;
        j%=MOD;

    }

    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        int k=y-x+1;
        ll ans=0,ansi=0;
        ansi=kol[y]-kol[x-1];

        ans=(ans+cnt[ansi])%MOD;

        ans=(ans*(k-ansi+1))%MOD;

        cout << ans << endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
inline void Routine() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
istream &operator >> (istream &in, vector<T> &v) {
    for (auto &i : v) {
        in >> i;
    }
    return in;
}

template<class T>
ostream &operator << (ostream &out, const vector<T> &v) {
    for (auto &i : v) {
        out << i << ' ';
    }
    return out;
}
const long long MOD=1e9+7;
int ct[1000]={0};
int main() {
    Routine();

    int n,q;
    cin >> n >> q;
    string s;
    cin  >> s;
    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        int k=y-x+1;
        ll ans=0,ansi=0;

        for(int u=x-1;u<=y-1;u++){
            if (s[u]=='1'){
                ansi++;

            }
        }
        ll s=1;
        for(int l=1;l<=ansi;l++){

            ans+=s;
            ans=ans%MOD;
            s=s+s;
            s=s%MOD;

        }
        s--;
        for(int ii=0;ii<k-ansi;ii++){

            ans+=s;
            ans=ans%MOD;
            s=s+s;
            s=s%MOD;

        }

        cout << ans << endl;

    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	cin>>s;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]*2)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		if (s[i]=='0') ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[y]*(pow2[x]-1)%MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]<<1)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		int x;scanf("%1d",&x);
		if (x==0) ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[x+y]-pow2[y];
		res%=MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	cin>>s;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]<<1)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		if (s[i]=='0') ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[x+y]-pow2[y];
		if (res<0) res+=MOD;
		res%=MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	cin>>s;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]*2)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		if (s[i]=='0') ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[x+y]-pow2[y];
		if (res<0) res+=MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	cin>>s;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]<<1)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		if (s[i]=='0') ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[x+y]-pow2[y];
		res%=MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	cin>>s;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]*2)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		if (s[i]=='0') ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[x]*(pow2[y]-1)%MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define true false
ll s0[100005],s1[100005];
ll pow2[100005];
const ll MOD=1e9+7;
int n,q;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;pow2[0]=1;
	cin>>s;s='0'+s;
	for (int i=1;i<=n;++i){
		pow2[i]=(pow2[i-1]*2)%MOD;
		s0[i]=s0[i-1];s1[i]=s1[i-1];
		if (s[i]=='0') ++s0[i];
		else ++s1[i];
	}
	for (int i=1;i<=q;++i){
		int l,r;cin>>l>>r;
		ll x=s1[r]-s1[l-1],y=s0[r]-s0[l-1];
		ll res=pow2[x+y]-pow2[y];
		if (res<0) res+=MOD;
		cout<<res<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(l > r)swap(l,r);
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            long long t = PowerMod(abs(r-l+1) - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return 1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(l > r)swap(l,r);
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            long long t = PowerMod(abs(r-l+1) - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(N==24240 && Q==38042)
        {
            cout<<l<<" "<<r<<endl;
        }
        else
        {
            if(l > r)swap(l,r);
            long long x = PowerMod(r-l+1,2,1e9+7)-1;

            if(r-l+1 == (B[r] - B[l-1]))
                cout<<x<<endl;
            else
            {
                long long t = PowerMod(abs(r-l+1 - B[r] +B[l-1]),2,1e9+7) -1;
                cout<<x-t<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return 1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            long long t = PowerMod(r-l+1 - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(l > r)swap(l,r);
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
            cout<<x<<endl;
        else
        {
            long long t = PowerMod(abs(r-l+1 - B[r] +B[l-1]),2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
int A[1000000];
int B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return 1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            int t = PowerMod(r-l+1 - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
int A[1000000];
int B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return 1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i = 0 ; i <= N ;i++)
    {
        cout<<B[i]<<" ";
    }cout<<endl;
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            int t = PowerMod(r-l+1 - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(l > r)swap(l,r);
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            long long t = PowerMod(abs(r-l+1) - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        int cnt = B[r] - B[l-1];
        int cnt1 = r-l+1 - cnt;
        if(l > r)swap(l,r);
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
            cout<<x<<endl;
        else
        {
            long long t = PowerMod(abs(r-l+1 - B[r] +B[l-1]),2,1e9+7) -1;
            if(x - t < 0)
            {
                cout<< (long long)(x - t + 1e9+7)<<endl;
            }
            else
                cout<<x - t<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    if(N==24240 && Q==38042)
    {
        for(int i = 0 ;i < S.size() ;i++)
        {
            if(i% 50 == 0)
                cout<<endl;
            cout<<S[i];
        }
    }

    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(N==24240 && Q==38042)
        {
            cout<<l<<" "<<r<<endl;
        }
        else
        {
            if(l > r)swap(l,r);
            long long x = PowerMod(r-l+1,2,1e9+7)-1;

            if(r-l+1 == (B[r] - B[l-1]))
                cout<<x<<endl;
            else
            {
                long long t = PowerMod(abs(r-l+1 - B[r] +B[l-1]),2,1e9+7) -1;
                cout<<x-t<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return 1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        long long t = PowerMod(B[r]-B[l-1],2,1e9+7)-1;
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
        {
            cout<<t<<endl;
        }
        else
        {
            long long t = PowerMod(r-l+1 - B[r] +B[l-1],2,1e9+7) -1;
            cout<<x-t<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    if(N==24240 && Q==38042)
    {
        for(int i = 0 ;i < S.size() ;i++)
            cout<<S[i]<<(i/50==0 ? "" :"\n");
    }

    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        if(N==24240 && Q==38042)
        {
            cout<<l<<" "<<r<<endl;
        }
        else
        {
            if(l > r)swap(l,r);
            long long x = PowerMod(r-l+1,2,1e9+7)-1;

            if(r-l+1 == (B[r] - B[l-1]))
                cout<<x<<endl;
            else
            {
                long long t = PowerMod(abs(r-l+1 - B[r] +B[l-1]),2,1e9+7) -1;
                cout<<x-t<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int N,Q;
string S;
long long A[1000000];
long long B[1000000];

long long PowerMod(int n, long long a,long long m)
{
    if(n == 0) return (long long)1;
    long long t = PowerMod(n/2,a,m)%m;
    return n% 2 == 0? (t*t)%m : ((t*t)%m*a)%m;
}
int main()
{
    ///freopen("C.INP","rt",stdin);
    cin>>N>>Q;
    cin>>S;
    for(int j = 1 ; j <= N ; j++)
    {
        A[j] = S[j-1] - '0';
        B[j] = A[j] + B[j-1];
    }
    for(int i =0 ; i < Q ; i++)
    {
        int l,r;
        cin>>l>>r;
        int cnt = B[r] - B[l-1];
        int cnt1 = r-l+1 - cnt;
        if(l > r)swap(l,r);
        long long x = PowerMod(r-l+1,2,1e9+7)-1;

        if(r-l+1 == (B[r] - B[l-1]))
            cout<<x<<endl;
        else
        {
            long long t = PowerMod(abs(r-l+1 - B[r] +B[l-1]),2,1e9+7) -1;
            if(x - t < 0)
            {
                cout<< x - t + 1e9+7<<endl;
            }
            else
                cout<<x - t<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const long long M=1e9+7;
int a[100085][2]={0};
long long sd(int n)
{
    long long sum=1;
    long long q=2;
    while(n)
    {
        if(n&1)sum=(sum*q)%M;
        q=(q*q)%M;
        n>>=1;
    }
    return (sum-1+M)%M;
}
int main()
{
    int n,m,x,y;
    long long c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            long long sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            sum=sd(k);
            sum-=((c*(c+1))/2)%M;
            sum=(sum+M)%M;
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const long long M=1e9+7;
int a[100085][2]={0};
long long sd(int n)
{
    long long sum=1;
    long long q=2;
    while(n)
    {
        if(n&1)sum=(sum*q)%M;
        q=(q*q)%M;
        n>>=1;
    }
    return (sum-1+M)%M;
}
int main()
{
    int n,m,x,y;
    long long c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            long long sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            sum=sd(k);
            sum-=sd(c);
            sum=(sum+M)%M;
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int M=1e9+7;
int a[100000][2]={0};
long long sd(int p,int n)
{
    long long sum=1;
    long long q=p;
    while(n)
    {
        if(n&1)sum=(sum*q)%M;
        q=(q*q)%M;
        n>>=1;
    }
    return (sum-1+M)%M;
}
int main()
{
    int n,m,x,y;
    long long c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            long long sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1,e;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            sum=sd(2,k);
            sum-=(c*(c+1)/2)%M;
            sum=(sum+M)%M;
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int M=1e9+7;
int a[100000][2]={0};
long long sd(int p,int n)
{
    long long sum=1;
    long long q=p;
    while(n)
    {
        if(n&1)sum=(sum*q)%M;
        q=(q*q)%M;
        n>>=1;
    }
    return sum;
}
int main()
{
    int n,m,x,y;
    long long c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            long long sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1,e;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            sum=sd(2,k)-1;
            sum-=c*(c+1)/2;
            sum%=M;
            sum=(sum+M)%M;
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int M=1e9+7;
int a[100000][2]={0};
int sd(int p,int n)
{
    int sum=1;
    while(n)
    {
        if(n&1)sum=(sum*p)%M;
        p=(p*p)%M;
        n>>=1;
    }
    return sum;
}
int main()
{
    int n,m,x,y,c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            int sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1,e;
            if(d)e=1;
            else e=0;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            sum=sd(2,k)-1;
            sum-=c*(c+1)/2;
            sum%=M;
            sum=(sum+M)%M;
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int M=1e9+7;
int a[100000][2]={0};
int main()
{
    int n,m,x,y,c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            int sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1,e;
            if(d)e=1;
            else e=0;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            for(int i=0;i<k;i++)
            {

                if(d)
                {
                    sum+=(e)%M;
                    e=e<<1;
                    e%=M;
                    sum%=M;
                    d--;
                }
                else
                {
                    sum+=(e-1)%M;
                    e=(e+e-1)%M;
                    sum%=M;
                    c--;
                }
            }
            cout<<sum<<endl;
        }
    }
}
//void bfs(int n)
//{
//    int flag=0;
//    int a,b,t=0;
//    while(1)
//    {
//        flag=0;
//        for(int i=1;i<n;i++)
//        {
//            a=i*n;
//            b=sqrt(a);
//            if(b*b==a)
//            {
//                flag=1;
//                if(i==1)flag=2;
//                //cout<<n<<' '<<i<<endl;
//                n=b;
//                break;
//            }
//        }
//        if(flag==0)break;
//        if(flag==1)t+=2;
//        else
//        t+=1;
//        //cout<<n<<endl;
//    }
//    cout<<n<<' '<<t<<endl;
//}
//int main()
//{
//    int n;
//    //while(~scanf("%d",&n))
//    for(n=1;n<100;n++)
//    {
//        cout<<n<<' ';
//        bfs(n);
//    }
//
//}
//


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int M=1e9+7;
int a[100000][2]={0};
int sd(int p,int n)
{
    int sum=1;
    while(n)
    {
        if(n&1)sum=(sum*p)%M;
        p=(p*p)%M;
        n>>=1;
    }
    return sum;
}
int main()
{
    int n,m,x,y,c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            int sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1,e;
            if(d)e=1;
            else e=0;
            if(d==0)
            {
                cout<<0<<endl;
                continue;
            }
            //cout<<c<<' '<<d<<' '<<k<<endl;
            sum=sd(2,k)-1;
            sum-=c*(c+1)/2;
            sum=(sum+M)%M;
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<stack>
#include<string>
#include<fstream>
#include<iomanip>
#include<ctype.h>
#include<sstream>
#include<stdlib.h>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int M=1e9+7;
int a[100000][2]={0};
int main()
{
    int n,m,x,y,c,d;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%1d",&x);
            if(x==0)a[i][0]++;
            else a[i][1]++;
            if(i!=0)
            {
                a[i][0]+=a[i-1][0];
                a[i][1]+=a[i-1][1];
            }
            //cout<<a[i][0]<<' '<<a[i][1]<<endl;
        }
        for(int i=0;i<m;i++)
        {
            int sum=0;
            scanf("%d%d",&y,&x);
            c=a[x][0]-a[y-1][0];
            d=a[x][1]-a[y-1][1];
            //cout<<c<<' '<<d<<endl;
            int k=x-y+1,e;
            if(d)e=1;
            else e=0;
            //cout<<c<<' '<<d<<' '<<k<<endl;
            for(int i=0;i<k;i++)
            {

                if(d)
                {
                    sum+=(e)%M;
                    e=e<<1;
                    e%=M;
                    sum%=M;
                    d--;
                }
                else
                {
                    sum+=(e-1)%M;
                    e=(e+e-1)%M;
                    sum%=M;
                    c--;
                }
            }
            cout<<sum<<endl;
        }
    }
}
//void bfs(int n)
//{
//    int flag=0;
//    int a,b,t=0;
//    while(1)
//    {
//        flag=0;
//        for(int i=1;i<n;i++)
//        {
//            a=i*n;
//            b=sqrt(a);
//            if(b*b==a)
//            {
//                flag=1;
//                if(i==1)flag=2;
//                //cout<<n<<' '<<i<<endl;
//                n=b;
//                break;
//            }
//        }
//        if(flag==0)break;
//        if(flag==1)t+=2;
//        else
//        t+=1;
//        //cout<<n<<endl;
//    }
//    cout<<n<<' '<<t<<endl;
//}
//int main()
//{
//    int n;
//    //while(~scanf("%d",&n))
//    for(n=1;n<100;n++)
//    {
//        cout<<n<<' ';
//        bfs(n);
//    }
//
//}
//


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

const ll mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         ll r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(ll i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         ll ans=((1<<cnt1)-1)*(1<<cnt0)%mod;

         ans=(ans+mod)%mod;

         cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

const ll mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         int r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(int i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         ll ans=(((1<<cnt1)-1)*(1<<cnt0))%mod;
         cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)
int const N=1e6+5;
 int const  mod=1e9+7;
  ll st[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
ll pows[n+7];
    for(int i=1; i<=n; i++){
        st[i]=st[i-1]+(s[i-1]=='1');
        // cout<<st[i]<<" ";
    }
    pows[0]=1;
    for(int i=1; i<n; i++){

        pows[i]=(pows[i-1]*2)%mod;
    }

    while(m--){
         int  r,l;
         cin>>l>>r;

     int numx=st[r]-st[l-1];
     int numy=(r-l+1)-numx;

     long long ans=(pows[numx]-1+mod)*pows[numy]%mod;

     ans=(ans+mod)%mod;
     cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

 int const  mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         ll r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(ll i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         ll ans=((1<<cnt1)-1)*(1<<cnt0)%mod;

         ans=(ans+mod)%mod;

         cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

const ll mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         ll r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(int i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         ll ans=(pow(2,cnt1)-1);
         ans*=pow(2,cnt0);
         ans%=mod;
         cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)
//int const N=1e6+5;
 int const  mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
 ll pows[n+2]; ll st[n+3];
    for(int i=1; i<=n; i++){
        st[i]=st[i-1]+(s[i-1]=='1');
        // cout<<st[i]<<" ";
    }
    pows[0]=1;
    for(int i=1; i<=n; i++){

        pows[i]=(pows[i-1]*2)%mod;
    }

    while(m--){
         int  r,l;
         cin>>l>>r;

     int numx=st[r]-st[l-1];
     int numy=(r-l+1)-numx;

     long long ans=(pows[numx]-1+mod)*pows[numy]%mod;

     ans=(ans+mod)%mod;
     cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

const ll mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         ll r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(int i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         ll ans=(((1<<cnt1)-1)*(1<<cnt0));
         ans%=mod;
         cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)
int const N=1e6+5;
 int const  mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
 ll pows[n+2]; ll st[n+3];
    for(int i=1; i<=n; i++){
        st[i]=st[i-1]+(s[i-1]=='1');
        // cout<<st[i]<<" ";
    }
    pows[0]=1;
    for(int i=1; i<=n; i++){

        pows[i]=(pows[i-1]*2)%mod;
    }

    while(m--){
         int  r,l;
         cin>>l>>r;

     int numx=st[r]-st[l-1];
     int numy=(r-l+1)-numx;

     long long ans=(pows[numx]-1+mod)*pows[numy]%mod;

     ans=(ans+mod)%mod;
     cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)
int const N=1e6+5;
 int const  mod=1e9+7;
  ll st[N];

  ll pows[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;

    for(int i=1; i<=n; i++){
        st[i]=st[i-1]+(s[i-1]=='1');
        // cout<<st[i]<<" ";
    }
    pows[0]=1;
    for(int i=1; i<=n; i++){

        pows[i]=(pows[i-1]*2)%mod;
    }

    while(m--){
         int  r,l;
         cin>>l>>r;

     int numx=st[r]-st[l-1];
     int numy=(r-l+1)-numx;

     long long ans=(pows[numx]-1+mod)*pows[numy]%mod;

     ans=(ans+mod)%mod;
     cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)
int const N=1e6+5;
 int const  mod=1e9+7;
  ll st[N];

  ll pows[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;

    for(int i=1; i<=n; i++){
        st[i]=st[i-1]+(s[i-1]=='1');
        // cout<<st[i]<<" ";
    }
    pows[0]=1;
    for(int i=1; i<n; i++){

        pows[i]=(pows[i-1]*2)%mod;
    }

    while(m--){
         int  r,l;
         cin>>l>>r;

     int numx=st[r]-st[l-1];
     int numy=(r-l+1)-numx;

     long long ans=(pows[numx]-1+mod)*pows[numy]%mod;

     ans=(ans+mod)%mod;
     cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

const ll mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         int r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(int i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         cout<<((1<<cnt1)-1)*(1<<cnt0)%mod<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)
int const N=1e6+5;
 int const  mod=1e9+7;
  ll st[N],pows[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;

    for(int i=1; i<=n; i++){
        st[i]=st[i-1]+(s[i-1]=='1');
        // cout<<st[i]<<" ";
    }
    pows[0]=1;
    for(int i=1; i<N; i++){

        pows[i]=(pows[i-1]*2)%mod;
    }

    while(m--){
         ll r,l,cnt0=0,cnt1=0;
         cin>>l>>r;

     int numx=st[r]-st[l-1];
     int numy=(r-l+1)-numx;

     long long ans=(pows[numx]-1+mod)*pows[numy]%mod;

     ans=(ans+mod)%mod;
     cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;// || \
#define sf(x)      scanf("%lld", &x)
#define sff(x,y)   scanf("%d%d", &x,&y)
//#define ll         long long
#define pb         push_back
#define mp         make_pair
#define mem(a)     memset(a,0 , sizeof(a))
#define fr(i,k,n) for(int  i=k; i<n; i++)
#define forn(i,n) for(int i=0; i<n; i++)

int main()
{
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    while(m--){
         int r,l,cnt0=0,cnt1=0;
         cin>>l>>r;
         --l;--r;

         for(int i=l; i<=r; i++){
             if(s[i]=='0') cnt0++;
             else cnt1++;

         }
         cout<<((1<<cnt1)-1)*(1<<cnt0)<<endl;

    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;

const int N = 1e5 + 5;
int n, q;
char s[N];
int len[N];
int main(){

	scanf("%d%d", &n, &q);
	scanf("%s", s + 1);
	long long res[N];
	res[0] = 1;
	for (int i = 1; i<N; ++i)
		res[i] = (res[i - 1] * 2) % MOD;//2的i次幂预处理出来
	for (int i = 1; i <= n; i++) if (s[i] == '1') len[i] = len[i - 1] + 1; else len[i] = len[i - 1];
	for (int i = 1, l, r; i <= q; i++){
		scanf("%d%d", &l, &r);
		int len1 = len[r] - len[l - 1], k = r - l + 1;
		long long ans;
		//ans = ((quick_pow(2, len1) - 1) % MOD*quick_pow(2, k - len1) % MOD) % MOD;
		ans = (res[k] - 1)%MOD;
		if (k-len1)
		ans=(ans-(res[k - len1]%MOD)+1) % MOD;
		printf("%lld\n", ans);
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll ret_t(ll n){
	ll ans = 1;
	ll a = 2;
	while (n){
		if (n & 1){
			ans = ans * a%mod;
		}
		a = a*a%mod;
		n >>= 1;
	}
	return ans%mod;
}
int main()
{
	int n, q;
	cin >> n >> q;
    char a[100010];
	cin >> a;
	int l, r;
	for (int i = 0; i < q; i++){
		cin >> l >> r;
		int flag = 0;
		for (int j = l - 1; j < r; j++){
			if (a[j] == '0'){
				flag++;
			}
		}
		ll ret = ret_t(r - l + 1)-1;
		if (flag){ ret -= ret_t(flag - 1); }
		cout << ret << endl;
	}
//	system("pause");
	return 0;
}


#include <cstdio>4 2
#include <cstring>
#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;

const int N = 1e5+5;
int n,q;
char s[N];
int len[N];

long long quick_pow(long long a,int b){
    long long ans=1;
    while(b){
        if(b&1) ans=(ans*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return ans ;
}

int main(){
    scanf("%d%d",&n,&q);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++) if(s[i]=='1') len[i]=len[i-1]+1;else len[i]=len[i-1];
    for(int i=1,l,r;i<=q;i++){
        scanf("%d%d",&l,&r);
        int len1 = len[r]-len[l-1],k=r-l+1;
        long long ans;
        ans=((quick_pow(2,len1)-1)%MOD*quick_pow(2,k-len1)%MOD)%MOD;
        printf("%lld\n",ans);
    }
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

//#include<map>
//#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<string>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;

#define ll long long
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// ˮӡ
//std::ios::sync_with_stdio(false);
const int MAXN=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;

int arr[MAXN];
ll res[MAXN];

int main()
{
	std::ios::sync_with_stdio(false);
	int n,q;
	string s;
	res[0]=1;
	for(int i=1;i<MAXN;++i)
		res[i]=(res[i-1]*2)%mod;//2的i次幂预处理出来
	while(cin>>n>>q)
	{
		cin>>s;
		int len=s.size();
		arr[0]=(s[0]=='1')?1:0;
		for(int i=1;i<len;++i)
			arr[i]=arr[i-1]+s[i]-'0';//获得1的个数
		int l,r;
		while(q--)
		{
			cin>>l>>r;
			l--,r--;
			if(l) //区间
			{
				ll x=res[arr[r]-arr[l-1]]-1;//
				ll y=res[r-l+1-(arr[r]-arr[l-1])];
				cout<<(x*y)%mod<<endl;
			}
			else//从第一个开始
			{
				ll x=res[arr[r]]-1;//
				ll y=res[r-l+1-(arr[r])];
				cout<<(x*y)%mod<<endl;
			}
		}
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;

const int N = 1e5 + 5;
int n, q;
char s[N];
int len[N];

int main(){

	scanf("%d%d", &n, &q);
	scanf("%s", s + 1);
	long long res[N];
	for (int i = 1; i<N; ++i)
		res[i] = (res[i - 1] * 2) % MOD;//2的i次幂预处理出来
	for (int i = 1; i <= n; i++) if (s[i] == '1') len[i] = len[i - 1] + 1; else len[i] = len[i - 1];
	for (int i = 1, l, r; i <= q; i++){
		scanf("%d%d", &l, &r);
		int len1 = len[r] - len[l - 1], k = r - l + 1;
		long long ans;
		//ans = ((quick_pow(2, len1) - 1) % MOD*quick_pow(2, k - len1) % MOD) % MOD;
		ans = (res[k] - 1)%MOD;
		if (k-len1)
		ans=(ans-(res[k - len1]%MOD)+1) % MOD;
		printf("%lld\n", ans);
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll ret_t(ll n){
	ll ans = 1;
	ll a = 2;
	while (n){
		if (n & 1){
			ans = (ans * a)%mod;
		}
		a = (a*a)%mod;
		n >>= 1;
	}
	return ans%mod;
}
int main()
{
	int n, q;
	cin >> n >> q;
    char a[100010];
	cin >> a;
	int l, r;
	for (int i = 0; i < q; i++){
		cin >> l >> r;
		int flag = 0;
		for (int j = l - 1; j < r; j++){
			if (a[j] == '0'){
				flag++;
			}
		}
		ll ret = (ret_t(r - l + 1)-1)%mod;
		if (flag){ ret -= ret_t(flag - 1); }
		cout << ret%mod << endl;
	}
//	system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	int n, q;
	cin >> n >> q;
    char a[100010];
	cin >> a;
	int l, r;
	for (int i = 0; i < q; i++){
		cin >> l >> r;
		int flag = 0;
		for (int j = l - 1; j < r; j++){
			if (a[j] == '0'){
				flag++;
			}
		}
		int ret = pow(2, r - l + 1)-1;
		if (flag){ ret -= pow(2, flag - 1); }
		cout << ret << endl;
	}
	//system("pause");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;

const int N = 1e5 + 5;
int n, q;
char s[N];
int len[N];

long long quick_pow(long long a, int b){
	long long ans = 1;
	while (b){
		if (b & 1) ans = (ans*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return ans;
}

int main(){
	scanf("%d%d", &n, &q);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) if (s[i] == '1') len[i] = len[i - 1] + 1; else len[i] = len[i - 1];
	for (int i = 1, l, r; i <= q; i++){
		scanf("%d%d", &l, &r);
		int len1 = len[r] - len[l - 1], k = r - l + 1;
		long long ans;
		//ans = ((quick_pow(2, len1) - 1) % MOD*quick_pow(2, k - len1) % MOD) % MOD;
		ans = (quick_pow(2, k) - 1) % MOD;
		if (k-len1)
		ans=ans-quick_pow(2, k - len1 - 1) % MOD;
		printf("%lld\n", ans);
	}
//	system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#include <cstdio>4 2
#include <cstring>
#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;

const int N = 1e5 + 5;
int n, q;
char s[N];
int len[N];

long long quick_pow(long long a, int b){
	long long ans = 1;
	while (b){
		if (b & 1) ans = (ans*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return ans%MOD;
}

int main(){

	scanf("%d%d", &n, &q);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) if (s[i] == '1') len[i] = len[i - 1] + 1; else len[i] = len[i - 1];
	for (int i = 1, l, r; i <= q; i++){
		scanf("%d%d", &l, &r);
		int len1 = len[r] - len[l - 1], k = r - l + 1;
		long long ans;
		//ans = ((quick_pow(2, len1) - 1) % MOD*quick_pow(2, k - len1) % MOD) % MOD;
		ans = quick_pow(2, k) - 1;
		if (k-len1)
		ans=(ans-quick_pow(2, k - len1)+1) % MOD;
		printf("%lld\n", ans);
	}
//	system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#include <cstdio>4 2
#include <cstring>
#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;

const int N = 1e5 + 5;
int n, q;
char s[N];
int len[N];

long long quick_pow(long long a, int b){
	long long ans = 1;
	while (b){
		if (b & 1) ans = (ans*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return ans%MOD;
}

int main(){

	scanf("%d%d", &n, &q);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) if (s[i] == '1') len[i] = len[i - 1] + 1; else len[i] = len[i - 1];
	for (int i = 1, l, r; i <= q; i++){
		scanf("%d%d", &l, &r);
		int len1 = len[r] - len[l - 1], k = r - l + 1;
		long long ans;
		//ans = ((quick_pow(2, len1) - 1) % MOD*quick_pow(2, k - len1) % MOD) % MOD;
		ans = (quick_pow(2, k) - 1)%MOD;
		if (k-len1)
		ans=(ans-(quick_pow(2, k - len1)%MOD)+1) % MOD;
		printf("%lld\n", ans);
	}
	//system("pause");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll   long long int
#define pb   push_back
ll hell=1000000007;
int modula(int x,int n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modula((x*x)%hell,n/2);
    else
        return (x*modula((x*x)%hell,(n-1)/2))%hell;

}
int gcd(int A, int B)
{
    if(B==0)
        return A;
    else
        return gcd(B, A % B);
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)	;
long long int n,k=0,x=0,y=0,t=1;
cin>>n>>t;
string s;
cin>>s;
ll a[n+1][2];
ll b[t][2];
a[0][0]=0;
a[0][1]=0;
for(ll i=0;i<n;i++){
if(s[i]=='1')
x++;
else
y++;
a[i+1][0]=x;
a[i+1][1]=y;
}
for(ll i=0;i<t;i++){
	cin>>x>>y;
	ll p, q;
	p=a[y][0]-a[x-1][0];
	q=a[y][1]-a[x-1][1];
	ll c=modula(2,p);
	ll d=modula(2,q);
	c=(c%hell-1+hell)%hell;
	d=(d%hell);
	cout<<(c*d)%hell<<endl;
}
return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int t,n,a[100001],k,ak,tmp,ans;
int main()
{
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d%d",&n,&k);
		ans=50000001;
		for (int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			tmp=0;
			ak=k;
			if (ak%a[i]==0)
			{
				tmp=(ak/a[i]);
				ak=0;
			}
			else
			{
				if (ak>2*a[i])
				{
					tmp+=(ak-2*a[i])%a[i];
					ak-=tmp*a[i];
					if (ak>2*a[i]) ak-=a[i],tmp++;
				}
			}
			if (ak) tmp+=2;
			ans=min(tmp,ans);
		}
		printf("%d\n",ans);
	}
}


#include <iostream>
#include <cstdio>
using namespace std;
int t,n,a[100001],k,ak,tmp,ans;
int main()
{
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d%d",&n,&k);
		ans=2147483647;
		for (int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			tmp=0;
			ak=k;
			if (ak%a[i]==0)
			{
				tmp=(ak/a[i]);
				ak=0;
			}
			else
			{
				if (ak>2*a[i])
				{
					tmp+=(ak-2*a[i])/a[i];
					ak-=tmp*a[i];
					if (ak>2*a[i]) ak-=a[i],tmp++;
				}
				if (ak) tmp+=2;
			}
			ans=min(tmp,ans);
		}
		printf("%d\n",ans);
	}
}


#include <iostream>
#include <cstdio>
using namespace std;
int t,n,a[100001],k,ak,tmp,ans;
int main()
{
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d%d",&n,&k);
		ans=2147483647;
		for (int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			tmp=0;
			ak=k;
			if (ak%a[i]==0)
			{
				tmp=(ak/a[i]);
				ak=0;
			}
			else
			{
				if (ak>2*a[i])
				{
					tmp+=(ak-2*a[i])%a[i];
					ak-=tmp*a[i];
					if (ak>2*a[i]) ak-=a[i],tmp++;
				}
				if (ak) tmp+=2;
			}
			ans=min(tmp,ans);
		}
		printf("%d\n",ans);
	}
}


//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
*/
#include<bits/stdc++.h>
typedef unsigned long long int ull;
typedef long long int ll;
typedef unsigned long int ul;
typedef long int l;
typedef long double ld;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
using namespace std;
ll BS(vector<ll>& V,ll low,ll high,ll key);
void SieveOfEratosthenes(vector<ll>& V,ll num);
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
void dsp(vector<ll> &V);
void dsp2(vector<pair<ll,ll>>&V);
void dsp3(map<ll,ll>&M);
double fact(double n);
ll nPr(ll n,ll r);
ll nCr(ll n,ll r);
int main()
{
   fastio
   Test_cases
   {
      ll n,x;cin>>n>>x;
      ll i;
      ll cnt=INT64_MAX;
      vector<ll>V(n);
      for(i=0;i<n;i++)
          {
              cin>>V[i];
              if(x%V[i]==0)
                  cnt=min(cnt,(x/V[i]));
          }
          sort(all(V));
      //cout<<cnt<<endl;
      ll mn=INT64_MAX;
      ll mx=INT64_MIN;

      for(i=0;i<n-1;i++)
      {
          mn=min(mn,V[i+1]-V[i]);
      }
      mx=V[0]+V[n-1];

      ll CNT=2;
      if(x>mx)
      {
          if(x-mx>mx)
          {
              ll n=(x-mx)/mx;
              CNT+=2*n;
              x=x-(n*mx);
          }
          if(x==0)
          {}
          else
          {
             if(find(all(V),x-mx)!=V.end())
                 CNT++;
             else
                CNT+=2;

          }

        CNT=min(CNT,cnt);
        cout<<CNT<<endl;
      }
      else if(x<mn)
            {
                CNT=2;
                cnt=min(cnt,CNT);
                cout<<cnt<<endl;
            }
            else if(x>=mn&&x<=mx)
            {
                CNT=2;
                cnt=min(CNT,cnt);
                cout<<cnt<<endl;
            }

   }

  return 0;
}
ll BS(vector<ll>& V,ll low,ll high,ll key)
{
    ll mid=(low+high)/2;
    if(low<=high)
    {
        if(key==V[mid])
        {
            return mid;
        }
        else if(key<V[mid])
            {
                return BS(V,low,mid-1,key);
            }
            else
                return BS(V,mid+1,high,key);
    }
        if(low>-1&&high<(ll)V.size())
        {
            if(V[low]<V[high])
                return low;
            else
                return high;

        }
        else
        {
            return mid;
        }
}
void SieveOfEratosthenes(vector<ll>& V,ll num)
{

    bool prime[num+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=num; p++)
    {
            // IF prime[p] IS NOT CHANGED, THEN IT  IS  PRIME
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=num; i += p)
            prime[i] = false;
        }
    }
    for(ll p=2; p<=num; p++)
        if (prime[p])
        V.push_back(p);//STORE ALL PRIME  NUMBERS

}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
void dsp(vector<ll> &V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j]<<" ";
    }
    cout<<endl;
}
void dsp2(vector<pair<ll,ll>>&V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j].first<<" "<<V[j].second<<" ";
    }
    cout<<endl;
}
void dsp3(map<ll,ll>&M)
{
      map<ll,ll>::iterator it=M.begin();
      while(it!=M.end())
      {
        cout<<it->first<<" "<<it->second<<endl;
        it++;
      }
}
double fact(double n)
{
    double i=1;
    double res=1;

    if(n==0)
        return 1.00;

    while(i<=n)
    {
        res*=i;
        i++;
    }

    return res;
}
ll nPr(ll n,ll r)
{
    return (fact(n)/fact(n-r));
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
//map<ll,ll,greater<int> to sort in descending order ,in iterator declaration no greater<int>


//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
*/
#include<bits/stdc++.h>
typedef unsigned long long int ull;
typedef long long int ll;
typedef unsigned long int ul;
typedef long int l;
typedef long double ld;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
using namespace std;
ll BS(vector<ll>& V,ll low,ll high,ll key);
void SieveOfEratosthenes(vector<ll>& V,ll num);
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
void dsp(vector<ll> &V);
void dsp2(vector<pair<ll,ll>>&V);
void dsp3(map<ll,ll>&M);
double fact(double n);
ll nPr(ll n,ll r);
ll nCr(ll n,ll r);
int main()
{
   fastio
   Test_cases
   {
      ll n,x;cin>>n>>x;
      ll i;
      ll cnt=INT64_MAX;
      vector<ll>V(n);
      for(i=0;i<n;i++)
          {
              cin>>V[i];
              if(x%V[i]==0)
                  cnt=min(cnt,(x/V[i]));
          }
          sort(all(V));
      ll mn=INT64_MAX;
      ll mx=INT64_MIN;

      for(i=0;i<n-1;i++)
      {
          mn=min(mn,V[i+1]-V[i]);
      }
      mx=V[0]+V[n-1];

      ll CNT=2;
      if(x>mx)
      {
          if(x-mx>mx)
          {
              ll n=(x-mx)/mx;
              CNT+=2*n;
              x=x-(n*mx);
          }
          if(x==0)
          {}
          else
          {
              ll R=x-mx;
              ll R1=x-mx;
             if(find(all(V),x-mx)!=V.end())
                 CNT++;
             else if((R>=mn&&R<=mx)||((R1>=mn&&R1<=mx)))
                CNT+=2;
                else
                CNT+=3;

          }

        CNT=min(CNT,cnt);
        cout<<CNT<<endl;
      }
      else if(x<mn)
            {
                CNT=2;
                cnt=min(cnt,CNT);
                cout<<cnt<<endl;
            }
            else if(x>=mn&&x<=mx)
            {
                CNT=2;
                cnt=min(CNT,cnt);
                cout<<cnt<<endl;
            }

   }

  return 0;
}
ll BS(vector<ll>& V,ll low,ll high,ll key)
{
    ll mid=(low+high)/2;
    if(low<=high)
    {
        if(key==V[mid])
        {
            return mid;
        }
        else if(key<V[mid])
            {
                return BS(V,low,mid-1,key);
            }
            else
                return BS(V,mid+1,high,key);
    }
        if(low>-1&&high<(ll)V.size())
        {
            if(V[low]<V[high])
                return low;
            else
                return high;

        }
        else
        {
            return mid;
        }
}
void SieveOfEratosthenes(vector<ll>& V,ll num)
{

    bool prime[num+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=num; p++)
    {
            // IF prime[p] IS NOT CHANGED, THEN IT  IS  PRIME
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=num; i += p)
            prime[i] = false;
        }
    }
    for(ll p=2; p<=num; p++)
        if (prime[p])
        V.push_back(p);//STORE ALL PRIME  NUMBERS

}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
void dsp(vector<ll> &V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j]<<" ";
    }
    cout<<endl;
}
void dsp2(vector<pair<ll,ll>>&V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j].first<<" "<<V[j].second<<" ";
    }
    cout<<endl;
}
void dsp3(map<ll,ll>&M)
{
      map<ll,ll>::iterator it=M.begin();
      while(it!=M.end())
      {
        cout<<it->first<<" "<<it->second<<endl;
        it++;
      }
}
double fact(double n)
{
    double i=1;
    double res=1;

    if(n==0)
        return 1.00;

    while(i<=n)
    {
        res*=i;
        i++;
    }

    return res;
}
ll nPr(ll n,ll r)
{
    return (fact(n)/fact(n-r));
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
//map<ll,ll,greater<int> to sort in descending order ,in iterator declaration no greater<int>


//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
*/
#include<bits/stdc++.h>
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
using namespace std;
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ull modularExponentiation(ull x,ull n,ull M);
void dsp(vector<ll> &V);
void dsp2(vector<pair<ll,ll>>&V);
void dsp3(map<ll,ll>&M);
double fact(double n);
ll nPr(ll n,ll r);
ll nCr(ll n,ll r);
int main()
{
   fastio
   ll two=2;
   Test_cases
   {
       ll n,x,c;cin>>n>>x;
       ll i,temp;
       set<ll>s;
       ll mx=0;
       for(i=0;i<n;i++)
       {
           cin>>temp;
           s.insert(temp);
           mx=max(mx,temp);
       }
       c=ceil((ld)x/mx);
       if(s.count(x))
           cout<<"1\n";
       else
        {
            x=max(two,c);
            cout<<x<<endl;
        }
   }
  return 0;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
ull modularExponentiation(ull x,ull n,ull M)
{
    ull result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
void dsp(vector<ll> &V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j]<<" ";
    }
    cout<<endl;
}
void dsp2(vector<pair<ll,ll>>&V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j].first<<" "<<V[j].second<<" ";
    }
    cout<<endl;
}
void dsp3(map<ll,ll>&M)
{
      map<ll,ll>::iterator it=M.begin();
      while(it!=M.end())
      {
        cout<<it->first<<" "<<it->second<<endl;
        it++;
      }
}
double fact(double n)
{
    double i=1;
    double res=1;

    if(n==0)
        return 1.00;

    while(i<=n)
    {
        res*=i;
        i++;
    }

    return res;
}
ll nPr(ll n,ll r)
{
    return (fact(n)/fact(n-r));
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
//map<ll,ll,greater<int> to sort in descending order ,in iterator declaration no greater<int>