#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const long long mod = 1e9 + 7;
long long m[maxn], pre[maxn];
char s[maxn];
int sum[maxn];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  scanf("%s", s + 1);
  m[0] = 1;
  long long base = 1;
  for (int i = 1; i <= n; i++) {
    base *= 2;
    base %= mod;
    m[i] = (m[i - 1] + base) % mod;
  }
  pre[0] = 1;
  for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] + m[i]) % mod;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1')
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1];
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    int high = r - l - 1;
    int low = r - l - sum[r] + sum[l - 1];
    if (l == r) {
      if (s[l] == '1')
        printf("1\n");
      else
        printf("0\n");
      continue;
    }
    if (sum[r] - sum[l - 1] == 0)
      printf("0\n");
    else {
      int num = sum[r] - sum[l - 1];
      if (low <= 0)
        printf("%lld\n", (pre[high] + num) % mod);
      else
        printf("%lld\n", ((pre[high] - pre[low - 1] + mod) % mod + num) % mod);
    }
  }
  return 0;
}
