#include <bits/stdc++.h>
int main() {
  size_t n = 0, q = 0;
  std::cin >> n;
  std::vector<int> s(n);
  for (size_t i = 0; i < n; ++i) {
    char c;
    std::cin >> c;
    s[i] = int(c - '0');
  }
  size_t sum = 0;
  std::vector<int> sums(n + 1);
  sums[0] = 0;
  for (size_t i = 1; i < n + 1; ++i) {
    sum += s[i - 1];
    sums[i] = sum;
  }
  std::cin >> q;
  for (size_t i = 0; i < q; ++i) {
    size_t a, b;
    std::cin >> a >> b;
    size_t sum = sums[b] - sums[a - 1];
    std::cout << sum / 10 << std::endl;
  }
  return 0;
}
