#include <bits/stdc++.h>
using namespace std;
char str[1008611];
long long s1[1008611], s2[1008611];
long long pow_(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    b >>= 1;
    a = (a * a) % 1000000007;
  }
  return ans;
}
long long inv(long long x) { return pow_(x, 1000000007 - 2); }
int main() {
  int n, q;
  cin >> n >> q;
  cin >> str;
  if (str[0] == '0') {
    s1[0] = 1;
    s2[0] = 0;
  } else {
    s1[0] = 0;
    s2[0] = 1;
  }
  for (int i = 1; i < n; i++) {
    s1[i] = s1[i - 1];
    s2[i] = s2[i - 1];
    if (str[i] == '0') {
      s1[i] = (s1[i] + 1) % 1000000007;
    } else {
      s2[i] = (s2[i] + 1) % 1000000007;
    }
  }
  long long n1, n2;
  while (q--) {
    int l, r;
    cin >> l >> r;
    n1 = (s1[r - 1] - s1[l - 1]) % 1000000007;
    n2 = (s2[r - 1] - s2[l - 1]) % 1000000007;
    if (str[l - 1] == '0') {
      n1 = (n1 + 1) % 1000000007;
    } else {
      n2 = (n2 + 1) % 1000000007;
    }
    long long a, b;
    a = pow_(2, n2) - 1;
    a = a % 1000000007;
    b = ((pow_(2, n1) - 1) * a);
    b = (b + 1000000007) % 1000000007;
    long long sum = (a + b) % 1000000007;
    cout << sum << endl;
  }
  return 0;
}
