#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int p2[21];
  p2[0] = 1;
  map<int, int> mp;
  mp[1] = 0;
  for (int i = 1; i < 21; i++) {
    p2[i] = 2 * p2[i - 1];
    mp[p2[i]] = i;
  }
  int dp[21][n][2];
  for (int len = 0; p2[len] <= n; len++) {
    for (int pos = 0; pos < n; pos++) {
      if (len == 0) {
        dp[len][pos][0] = a[pos];
        dp[len][pos][1] = 0;
      } else if (pos + p2[len - 1] < n) {
        int pos2 = pos + p2[len - 1];
        if (dp[len - 1][pos][0] + dp[len - 1][pos2][0] >= 10)
          dp[len][pos][1] = dp[len - 1][pos][1] + dp[len - 1][pos2][1] + 1;
        else
          dp[len][pos][1] = dp[len - 1][pos][1] + dp[len - 1][pos2][1];
        dp[len][pos][0] = (dp[len - 1][pos][0] + dp[len - 1][pos2][0]) % 10;
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    int range = r - l + 1;
    cout << dp[mp[range]][l][1] << endl;
  }
  return 0;
}
