#include <bits/stdc++.h>
using namespace std;
const long long N = 1e+5 + 1;
long long n, q, say, a[N], t[4 * N], sum;
void build(long long v, long long tl, long long tr) {
  if (tl > tr) return;
  if (tl == tr) {
    t[v] = a[tl];
    return;
  }
  long long tm = (tl + tr) / 2;
  build(v * 2, tl, tm);
  build(v * 2 + 1, tm + 1, tr);
  t[v] = t[v * 2] + t[v * 2 + 1];
}
void sums(long long v, long long tl, long long tr, long long old_value,
          long long new_value) {
  if (tl > tr) return;
  if (tl == tr) {
    if (t[v] == old_value) t[v] = new_value, say++;
    return;
  }
  long long tm = (tl + tr) / 2;
  sums(v * 2, tl, tm, old_value, new_value);
  sums(v * 2 + 1, tm + 1, tr, old_value, new_value);
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  build(1, 0, n - 1);
  sum = t[1];
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    say = 0;
    sums(1, 0, n - 1, l, r);
    sum += say * (r - l);
    cout << sum << '\n';
  }
  return 0;
}
