#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 100005;
long long q, n, l, r, ans;
char c;
long long sum[MAXN], sumPow[MAXN];
void init() {
  sumPow[0] = 1;
  long long temp = 1;
  for (int i = 1; i <= MAXN; i++) {
    temp = temp * 2 % MOD;
    sumPow[i] = (sumPow[i - 1] % MOD + temp % MOD) % MOD;
  }
}
int main() {
  ios::sync_with_stdio(false);
  init();
  cin >> n >> q;
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> c;
    sum[i] = sum[i - 1] + (c == '0' ? 1 : 0);
  }
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    int x = sum[r] - sum[l - 1];
    int size = r - l + 1;
    ans = (sumPow[size - 1] - (x == 0 ? 0 : sumPow[x - 1]) + MOD) % MOD;
    printf("%d\n", ans);
  }
  return 0;
}
