#include <bits/stdc++.h>
using namespace std;
const int SIZEN = 100010;
const long long mod = 1000000007;
int n, q;
int a[SIZEN] = {0};
long long qpow(long long x, long long len) {
  long long ret = 1;
  for (; len; len >>= 1) {
    if (len & 1) ret = ret * x % mod;
    x = x * x % mod;
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%1d", &a[i]), a[i] += a[i - 1];
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    long long ans = qpow(2, a[r] - a[l - 1]) - 1;
    ans += (qpow(2, r - l + 1 - a[r] + a[l - 1]) - 1) *
           (qpow(2, a[r] - a[l - 1]) - 1) % mod;
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
  }
  return 0;
}
