#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long pow_2[200010];
int a[200010];
int b[200010];
int main() {
  pow_2[0] = 1;
  for (long long i = 1; i <= 200000; i++) {
    pow_2[i] = (pow_2[i - 1] * 2) % mod;
  }
  fill(a, a + 100010, 0);
  fill(b, b + 100010, 0);
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%1d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1];
    if (a[i] == 1) b[i]++;
  }
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    long long s1 = b[r] - b[l - 1];
    long long s2 = r - l + 1 - s1;
    int a1 = (pow_2[s1] - 1);
    long long s = (a1 * (pow_2[s2] - 1)) % mod;
    s = (s + (pow_2[s1] - 1)) % mod;
    cout << s << endl;
  }
  return 0;
}
