#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N], st[4 * N], val[4 * N], m;
void build(int l = 0, int r = m - 1, int p = 1) {
  if (l == r) {
    st[p] = 0;
    val[p] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, 2 * p);
  build(mid + 1, r, 2 * p + 1);
  val[p] = (val[2 * p] + val[2 * p + 1]) % 10;
  st[p] = st[2 * p] + st[2 * p + 1] + (val[2 * p] + val[2 * p + 1] > 9);
}
pair<int, int> query(int a, int b, int l = 0, int r = m - 1, int p = 1) {
  if (b < l || r < a) return make_pair(0, 0);
  if (a <= l && r <= b) return make_pair(st[p], val[p]);
  int mid = (l + r) >> 1;
  pair<int, int> q1 = query(a, b, l, mid, 2 * p);
  pair<int, int> q2 = query(a, b, mid + 1, r, 2 * p + 1);
  return make_pair(q1.first + q2.first + (q1.second + q2.second > 9),
                   (q1.second + q2.second) % 10);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  m = 1;
  while (m < n) m <<= 1;
  build();
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    printf("%d\n", query(l, r).first);
  }
  return 0;
}
