#include <bits/stdc++.h>
using namespace std;
int n = 1e5 + 5;
vector<int> tree(n, 0);
long long int sum(int index) {
  index++;
  long long int s = 0;
  while (index > 0) {
    s += tree[index];
    index -= (index) & (-index);
  }
  return s;
}
void update(int val, int index) {
  index++;
  while (index <= n) {
    tree[index] += val;
    index += (index) & (-index);
  }
}
void make(int a[]) {
  for (int i = 0; i < n; i++) {
    update(a[i], i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  {
    cin >> n;
    int a[n];
    vector<int> v[100000 + 5];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      v[a[i]].push_back(i);
    }
    make(a);
    int q;
    cin >> q;
    while (q--) {
      int b, c;
      cin >> b >> c;
      for (int i = 0; i < (int)v[b].size(); i++) {
        if (v[b][i] != -1) {
          a[v[b][i]] = c;
          update(c - b, v[b][i]);
          v[b][i] = -1;
          v[c].push_back(i);
        }
      }
      cout << sum(n - 1) << '\n';
    }
  }
  return 0;
}
