#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
string s;
long long fastpow(int a, int b) {
  if (b == 0) return 1LL;
  if (b == 1) return 1LL * a;
  int tmp = fastpow(a, b / 2) * fastpow(a, b / 2) % 1000000007;
  if (b % 2 == 1)
    return tmp * a % 1000000007;
  else
    return tmp;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> n >> q;
  getline(cin, s);
  getline(cin, s);
  for (int i = 0; i < n; i++) a[i + 1] = a[i] + (s[i] == '1' ? 1 : 0);
  while (q--) {
    int l, r;
    cin >> l >> r;
    int k = a[r] - a[l - 1], K = r - l + 1 - k;
    long long res = (fastpow(2, k) - 1LL) * (fastpow(2, K) - 1) % 1000000007;
    res += fastpow(2, k) - 1LL;
    res %= 1000000007;
    cout << res << "\n";
  }
  return 0;
}
