#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> bit;
unordered_map<long long int, set<long long int>> m;
long long int sum(long long int r) {
  long long int ret = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
  return ret;
}
void add(long long int idx, long long int delta) {
  for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta;
}
signed main() {
  cin >> n;
  bit.assign(n, 0);
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
    add(i, v[i]);
    m[v[i]].insert(i);
  }
  long long int q, l = 0, r = n - 1;
  cin >> q;
  while (q--) {
    long long int c, b;
    cin >> b >> c;
    vector<long long int> to_erase;
    for (auto const &i : m[b]) add(i, c - b), to_erase.push_back(i);
    for (auto const &i : to_erase) {
      m[b].erase(i);
      m[c].insert(i);
    }
    cout << (sum(r) - sum(l - 1)) << endl;
  }
  return 0;
}
