#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int sum[1000100];
long long ans[1000100];
int main() {
  ans[0] = 1;
  for (int i = 1; i < 1000100; i++) {
    ans[i] = ans[i - 1] * 2;
    ans[i] %= MOD;
  }
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  for (int i = 1; i <= s.size(); i++) {
    sum[i] = s[i - 1] - '0';
    sum[i] += sum[i - 1];
  }
  for (int a, b, i = 0; i < q; i++) {
    cin >> a >> b;
    int y = sum[b] - sum[a - 1];
    int k = b - a + 1;
    y = k - y;
    cout << (ans[k] - ans[y] + MOD) % MOD << endl;
  }
  return 0;
}
