#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const long long mod = 1e9 + 7;
int cnt[maxn][2];
long long powMod(long long a, long long b) {
  long long sum = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2 == 1) sum = (sum * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int c0 = 0, c1 = 0;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      c0++;
    else
      c1++;
    cnt[i][0] = c0;
    cnt[i][1] = c1;
  }
  int l, r;
  while (m--) {
    cin >> l >> r;
    l--, r--;
    c0 = cnt[r][0] - cnt[l][0] + (s[l] == '0');
    c1 = cnt[r][1] - cnt[l][1] + (s[l] == '1');
    long long ans = powMod(2, c1) - 1;
    if (ans < 0) ans += mod;
    cout << powMod(2, c0) * ans % mod << endl;
  }
}
