#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int x = 0;
  while ((1 << x) < n) {
    x++;
  }
  vector<vector<pair<int, int> > > dp(n, vector<pair<int, int> >(x + 1));
  for (int i = 0; i < n; i++) {
    dp[i][0].first = 0;
    dp[i][0].second = arr[i];
  }
  for (int i = 1; i <= x; i++) {
    for (int j = 0; j < n; j++) {
      int l = j;
      int r = l + (1 << (i - 1));
      if (r >= n || dp[r][i - 1].first == -1) {
        dp[l][i].first = -1;
        dp[l][i].second = -1;
      } else {
        dp[l][i].first = dp[l][i - 1].first + dp[r][i - 1].first;
        dp[l][i].second = dp[l][i - 1].second + dp[r][i - 1].second;
        if (dp[l][i].second >= 10) {
          dp[l][i].first++;
          dp[l][i].second %= 10;
        }
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l;
    int r;
    cin >> l >> r;
    l--;
    r--;
    int len = r - l + 1;
    len = (int)log2(len);
    cout << dp[l][len].first << endl;
  }
  return 0;
}
