#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  int sum = 0;
  vector<int> a(N);
  vector<long long> ans;
  map<int, vector<int>> m;
  for (int i = 0; i < (N); ++i) {
    cin >> a[i];
    sum += a[i];
    m[a[i]].push_back(i);
  }
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < (m[b].size()); ++i) {
      m[c].push_back(m[b][i]);
      sum += c - a[m[b][i]];
      a[m[b][i]] = c;
    }
    m[b].clear();
    ans.push_back(sum);
  }
  for (int i = 0; i < (ans.size()); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
