#include <bits/stdc++.h>
using namespace std;
int a[222222], n, q, from, to;
long long tree[888888];
long long init(int node, int start, int end) {
  if (start == end) return tree[node] = a[start];
  return tree[node] = init(node * 2, start, start + end >> 1) +
                      init(node * 2 + 1, (start + end >> 1) + 1, end);
}
long long query(int node, int start, int end, int diff, int change) {
  if (!tree[node * 2] && !tree[node * 2 + 1]) {
    if (tree[node] == diff) return tree[node] = change;
    return tree[node];
  }
  return query(node * 2, start, start + end >> 1, diff, change) +
         query(node * 2 + 1, (start + end >> 1) + 1, end, diff, change);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  init(1, 1, n);
  cin >> q;
  while (q--) {
    cin >> from >> to;
    cout << query(1, 1, n, from, to) << '\n';
  }
}
