#include <bits/stdc++.h>
using namespace std;
const long long int K = 1e9 + 7;
long long int mu[100005];
int a[100005];
int s[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  mu[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    mu[i] = mu[i - 1] * 2ll % K;
  }
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    if (c == '1')
      a[i] = 1;
    else
      a[i] = 0;
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    int a = s[r] - s[l - 1];
    int b = r - l + 1 - a;
    long long int res = mu[b] * (mu[a] + K - 1) % K;
    cout << res << endl;
  }
  return 0;
}
