#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, m;
int num[N + 5][20], ans[N + 5][20];
int LGLOG2(int num) {
  for (int i = 0; i < 20; i++)
    if ((1 << i) == num) return i;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &num[i][0]);
  for (int siz = 1; siz < 20; siz++) {
    for (int i = 0; i < n; i++) {
      if (i + (1 << siz) > n) continue;
      int add = num[i][siz - 1] + num[i + (1 << siz - 1)][siz - 1];
      if (add >= 10)
        num[i][siz] = add - 10,
        ans[i][siz] = ans[i][siz - 1] + ans[i + (1 << siz - 1)][siz - 1] + 1;
      else
        num[i][siz] = add,
        ans[i][siz] = ans[i][siz - 1] + ans[i + (1 << siz - 1)][siz - 1];
    }
  }
  scanf("%d", &m);
  while (m--) {
    int lef, rig;
    scanf("%d%d", &lef, &rig);
    int siz = LGLOG2(rig - lef + 1);
    printf("%d\n", ans[lef - 1][siz]);
  }
  return 0;
}
