#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n >> q;
  vector<long long> powe(n + 1, 0);
  powe[0] = 1;
  for (long long i = 1; i <= n; i++) powe[i] = (powe[i - 1] * 2) % 1000000007;
  vector<long long> A(n, 0), pre(n, 0);
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++)
    if (s[i] == '1') A[i] = 1;
  for (long long i = 0; i < n; i++)
    pre[i] = A[i] + (i - 1 >= 0 ? pre[i - 1] : 0);
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    l--;
    r--;
    long long num = r - l + 1, one = pre[r] - (l - 1 >= 0 ? pre[l - 1] : 0);
    long long zer = num - one;
    long long val = powe[one] - 1;
    long long val2 = powe[zer] - 1;
    val = ((val + ((val * val2) % 1000000007) % 1000000007) % 1000000007 +
           2 * 1000000007) %
          1000000007;
    cout << val << endl;
  }
  return 0;
}
