#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int powers(long long int a, long long int b) {
  long long int ans = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % mod) * (a % mod)) % mod;
    b /= 2;
    a = ((a % mod) * (a % mod)) % mod;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q, l, r;
  cin >> n >> q;
  long long int arr[n], one[n + 1], zero[n];
  string second;
  cin >> second;
  for (int i = 0; i < n; i++) {
    if (second[i] == '1')
      arr[i] = 1;
    else
      arr[i] = 0;
  }
  one[0] = zero[0] = 0;
  for (int i = 1; i <= n; i++) {
    one[i] = one[i - 1] + arr[i - 1];
    zero[i] = zero[i - 1];
    if (!arr[i - 1]) zero[i]++;
  }
  while (q--) {
    cin >> l >> r;
    long long int ans = (powers(2, one[r] - one[l - 1]) - 1) % mod;
    long long int zans = (powers(2, zero[r] - zero[l - 1]) - 1) % mod;
    cout << (((zans + 1) % mod) * ans) % mod << endl;
  }
  return 0;
}
