#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, tes, t, f[100009], z, x, pas, dp[100009][20], za, xa,
    dp2[100009][20], l, r;
bool bo[100009][20];
void rec(int q, int w, int r) {
  if (bo[q][r] == 1) return;
  bo[q][r] = 1;
  if (q == w) {
    dp[q][r] = 0;
    dp2[q][r] = f[q];
    return;
  }
  rec(q, (q + w) / 2, r - 1);
  rec((q + w) / 2 + 1, w, r - 1);
  dp[q][r] += dp[q][r - 1] + dp[(q + w) / 2 + 1][r - 1];
  if (dp2[q][r - 1] + dp2[(q + w) / 2 + 1][r - 1] >= 10) dp[q][r]++;
  dp2[q][r] = (dp2[q][r - 1] + dp2[(q + w) / 2 + 1][r - 1]) % 10;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a;
  for (b = 1; b <= a; b++) cin >> f[b];
  cin >> tes;
  for (t = 1; t <= tes; t++) {
    cin >> l >> r;
    za = 1;
    xa = 1;
    while (1) {
      if (l + za - 1 == r) break;
      za *= 2;
      xa++;
    }
    rec(l, r, xa);
    cout << dp[l][xa] << endl;
  }
  return 0;
}
