#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 2147483647;
const long long MAXLL = 9223372036854775807LL;
const int MAX = 400000;
long long n, q, col, pref[MAX], l, r, sum, ans, t[MAX];
string s;
int main() {
  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') col++;
    pref[i] = col;
  }
  t[0] = 0;
  for (int i = 1; i <= 100005; i++)
    t[i] = (t[i - 1] + t[i - 1] + 1) % 1000000007;
  for (int i = 0; i < q; i++) {
    ans = 0, col = 0;
    cin >> l >> r;
    l--, r--;
    if (l == 0)
      sum = pref[r];
    else
      sum = pref[r] - pref[l - 1];
    if (t[r - l + 1] >= t[r - l + 1 - sum])
      ans += t[r - l + 1] - t[r - l + 1 - sum];
    else
      ans += t[r - l + 1] + 1000000007 - t[r - l + 1 - sum];
    cout << ans << '\n';
  }
  return 0;
}
