#include <bits/stdc++.h>
using namespace std;
void smain();
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  smain();
}
vector<long long> pf;
const long long N = 1 << 17;
const long long M = 1e9 + 7;
long long cnt[N];
inline long long MOD(long long v) {
  if (v < 0) {
    v %= M;
    return v < 0 ? v + M : v;
  }
  return v % M;
}
long long prog(long long l, long long r) { return (l + r) * (r - l + 1) / 2; }
long long hlp[N] = {0, 1};
long long quer(long long l, long long r) {
  l--, r--;
  long long first = pf[r];
  if (l) first -= pf[l - 1];
  if (!first) return 0;
  long long ans = cnt[r - l + 1] - 1;
  long long v = (r - l + 1) - first;
  return MOD(ans - hlp[v]);
}
void smain() {
  cnt[0] = 1;
  for (long long i = 1; i < N; ++i) cnt[i] = (cnt[i - 1] * 2) % M;
  for (long long i = 2; i < N; ++i) hlp[i] = MOD(hlp[i - 1] + cnt[i - 1]);
  long long n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  pf.resize(n);
  for (long long i = 0; i < n; ++i) pf[i] = s[i] - '0';
  for (long long i = 1; i < n; ++i) pf[i] += pf[i - 1];
  for (long long i = 0; i < q; ++i) {
    long long l, r;
    cin >> l >> r;
    cout << quer(l, r) << '\n';
  }
}
