#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<vector<pair<int, int> > > dp(20);
  int current_length = 1;
  for (int i = 0; i < s.size(); i++) {
    dp[0].push_back(make_pair(s[i], 0));
  }
  int deg;
  for (deg = 1; deg < 20; deg++) {
    current_length *= 2;
    for (int i = 0; i + current_length <= n; i++) {
      int left = dp[deg - 1][i].first;
      int right = dp[deg - 1][i + current_length / 2].first;
      int candies_left = dp[deg - 1][i].second;
      int candies_right = dp[deg - 1][i + current_length / 2].second;
      int candies = candies_left + candies_right;
      if ((left + right) >= 10) {
        candies++;
      }
      dp[deg].push_back(make_pair((left + right) % 10, candies));
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    deg = 0;
    int l, r;
    cin >> l >> r;
    int length = r - l + 1;
    while (length % 2 == 0) {
      deg++;
      length = length / 2;
    }
    cout << dp[deg][l - 1].second << "\n";
  }
}
