#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int N, A[MAXN + 10], Q;
int dp[20][MAXN + 10][2];
int main() {
  int i, j;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%d", &A[i]);
  for (i = 1; i <= N; i++) dp[0][i][1] = A[i];
  for (i = 1; (1 << i) <= N; i++) {
    int l = (1 << i);
    for (j = l; j <= N; j++) {
      dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j - (1 << (i - 1))][0] +
                    (dp[i - 1][j][1] + dp[i - 1][j - (1 << (i - 1))][1] >= 10);
      dp[i][j][1] = (dp[i - 1][j][1] + dp[i - 1][j - (1 << (i - 1))][1]) % 10;
    }
  }
  scanf("%d", &Q);
  while (Q--) {
    int s, e;
    scanf("%d%d", &s, &e);
    int l = e - s + 1;
    l = __builtin_ctz(l);
    printf("%d\n", dp[l][e][0]);
  }
}
