#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), cum(n + 1);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cum[i + 1] = a[i] + cum[i];
  }
  int bits = 32 - __builtin_clz(n);
  vector<vector<int>> dp(bits + 1, vector<int>(n));
  auto sum = [&](int l, int r) { return (cum[r] - cum[l]) % 10; };
  for (int bit = 0; bit < bits; bit++) {
    int len = 1 << bit;
    for (int i = 0; i + 2 * len <= n; i++) {
      dp[bit + 1][i] = dp[bit][i] + dp[bit][i + len] +
                       (sum(i, i + len) + sum(i + len, i + 2 * len)) / 10;
    }
  }
  int q;
  scanf("%d", &q);
  for (int qq = 0; qq < q; qq++) {
    int l, r;
    scanf("%d %d", &l, &r);
    --l;
    int bit = __builtin_ctz(r - l);
    printf("%d\n", dp[bit][l]);
  }
  return 0;
}
