#include <bits/stdc++.h>
using namespace std;
int delta[4][2] = {{-1, -0}, {0, 1}, {1, 0}, {0, -1}};
long long calc_pow(long long a, long long p, long long m = 1000000007) {
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = (res * a) % m;
    a = (a * a) % m;
    p >>= 1;
  }
  return res;
}
long long calc_pow_without_mod(long long a, long long p) {
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = res * a;
    a = a * a;
    p >>= 1;
  }
  return res;
}
void func() {
  long long n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  char arr[n + 1];
  for (int i = 0; i < n; i++) arr[i + 1] = s[i];
  long long pre[n + 1];
  for (int i = 0; i <= n; i++) pre[i] = 0;
  for (int i = 1; i <= (n); i++) {
    pre[i] = pre[i - 1];
    if (arr[i] == '1') pre[i]++;
  }
  for (int i = 1; i <= (q); i++) {
    int l, r;
    cin >> l >> r;
    long long ones = pre[r] - pre[l - 1];
    long long zeroes = r - l + 1 - ones;
    long long val = (calc_pow(2, ones) - 1 + 1000000007) % 1000000007;
    long long new_val = (calc_pow(2, zeroes) - 1 + 1000000007) % 1000000007;
    new_val = (new_val * val) % 1000000007;
    cout << (val + new_val) % 1000000007 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  func();
  return 0;
}
