#include <bits/stdc++.h>
using namespace std;
int gcd(int f, int s) {
  if (s == 0)
    return f;
  else
    return gcd(s, f % s);
}
int const N = 1007006;
long long const M = 1000 * 1000 * 1000 + 7;
long double const ep = .000000000000000001;
int arr[N];
long long pw[N];
int cul0[N], cul1[N];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    cul0[i] = cul0[i - 1];
    cul1[i] = cul1[i - 1];
    if (c == '0')
      arr[i] = 0, cul0[i]++;
    else
      arr[i] = 1, cul1[i]++;
  }
  pw[0] = 1;
  for (int i = 1; i < 1000000; i++) pw[i] = (pw[i - 1] * 2) % M;
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    int ones = cul1[r] - cul1[l];
    int zeros = cul0[r] - cul0[l];
    long long sum = pw[ones] - 1;
    sum = (sum + (sum * (pw[zeros] - 1)) % M) % M;
    printf("%lld\n", sum);
  }
  return 0;
}
