#include <bits/stdc++.h>
using namespace std;
int N;
int A[100005];
int psm[100005];
int DP[100005][20];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    psm[i] = (psm[i - 1] + A[i]) % 10;
  }
  for (int d = 1; d <= 17; d++) {
    if ((1 << d) > N) break;
    int l = (1 << d);
    for (int i = 1; i <= N; i++) {
      if (i + l - 1 > N) break;
      int m = i + l / 2 - 1;
      int r = i + l - 1;
      DP[i][d] =
          DP[i][d - 1] + DP[m + 1][d - 1] +
          ((psm[m] - psm[i - 1] + 10) % 10 + (psm[r] - psm[m] + 10) % 10 >= 10);
    }
  }
  int Q;
  int l, r;
  cin >> Q;
  while (Q--) {
    cin >> l >> r;
    int ln = (r - l + 1), d = 0;
    while (ln > 1) {
      d++, ln /= 2;
    }
    cout << DP[l][d] << '\n';
  }
  return 0;
}
