#include <bits/stdc++.h>
using namespace std;
struct nn {
  nn() : Sum(0), Candy(0) {}
  int Sum, Candy;
};
int Size;
nn Seg[500000];
void build(int node = 1, int beg = 1, int end = Size) {
  if (beg == end) {
    cin >> Seg[node].Sum;
    Seg[node].Candy = 0;
    return;
  }
  int mid = (beg + end) >> 1, left_node = node << 1, right_node = node << 1 | 1;
  build(left_node, beg, mid);
  build(right_node, mid + 1, end);
  Seg[node].Sum = (Seg[left_node].Sum + Seg[right_node].Sum) % 10;
  Seg[node].Candy = Seg[left_node].Candy + Seg[right_node].Candy;
  if (Seg[left_node].Sum + Seg[right_node].Sum >= 10) Seg[node].Candy += 1;
}
nn query(int L, int R, int node = 1, int beg = 1, int end = Size) {
  if (L <= beg && end <= R) {
    return Seg[node];
  }
  int mid = (beg + end) >> 1, left_node = node << 1, right_node = node << 1 | 1;
  nn tmp, tmp_left, tmp_right;
  if (L <= mid) tmp_left = query(L, R, left_node, beg, mid);
  if (mid < R) tmp_right = query(L, R, right_node, mid + 1, end);
  tmp.Sum = (tmp_left.Sum + tmp_right.Sum) % 10;
  tmp.Candy = (tmp_left.Candy + tmp_right.Candy);
  if (tmp_left.Sum + tmp_right.Sum >= 10) tmp.Candy += 1;
  return tmp;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  Size = n;
  build();
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << query(l, r).Candy << '\n';
  }
  return 0;
}
