#include <bits/stdc++.h>
using namespace std;
const int LIMIT = 1e5 + 7;
const int MOD = 1e9 + 7;
const int MAX = 1 << 30;
int n, q, l, r, dp[LIMIT], f[LIMIT];
char c;
int main() {
  scanf("%d %d\n", &n, &q);
  f[0] = 1;
  for (int i = 0; i < n; i++) {
    scanf("%c", &c);
    dp[i + 1] = dp[i] + (c - '0');
    f[i + 1] = f[i] * 2ll % MOD;
  }
  while (q--) {
    scanf("%d %d", &l, &r);
    unsigned long long ones = dp[r] - dp[l - 1];
    unsigned long long zeros = r - l + 1 - ones;
    unsigned long long ans = (f[ones] + MOD - 1ll) % MOD;
    ans = (ans * (unsigned long long)f[zeros]) % MOD;
    printf("%lld\n", ans);
  }
  return EXIT_SUCCESS;
}
