#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, K, q, L, R;
  cin >> n;
  K = 25;
  long long int a[n];
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  pair<long long int, long long int> st[n][K];
  for (long long int i = 0; i < n; i++) {
    st[i][0] = {a[i], 0};
  }
  for (long long int j = 1; j <= K; j++) {
    for (long long int i = 0; i + (1 << (j - 1)) < n; i++) {
      long long int vl =
          st[i][j - 1].first + st[i + (1 << (j - 1))][j - 1].first;
      st[i][j] = {vl % 10, ((vl >= 10) ? 1 : 0) + st[i][j - 1].second +
                               st[i + (1 << (j - 1))][j - 1].second};
    }
  }
  cin >> q;
  while (q--) {
    cin >> L >> R;
    L--;
    R--;
    long long int sum = 0;
    for (long long int j = K; j >= 0; j--) {
      if ((1 << j) <= R - L + 1) {
        sum += st[L][j].second;
        L += 1 << j;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
