#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
const int mod = 1e9 + 7;
int n, q;
char s[N];
long long sum[N];
long long pw[N], fibo[N], pw2[N], pw3[N];
int main() {
  scanf("%d%d", &n, &q);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + (s[i] == '1');
  }
  for (int i = 1; i <= 2e5; ++i) {
    if (i == 1)
      fibo[i] = 1;
    else
      fibo[i] = fibo[i - 1] * 2;
    fibo[i] %= mod;
    pw[i] = pw[i - 1] + fibo[i];
    pw[i] %= mod;
  }
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    long long num1 = sum[r] - sum[l - 1];
    long long num0 = (r - l + 1) - num1;
    long long ans = pw[num1];
    ans %= mod;
    if (num0) ans += pw[num1] * pw[num0] % mod;
    ans %= mod;
    printf("%lld\n", ans);
  }
}
