#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  int q;
  cin >> q;
  vector<ll> b(q);
  vector<ll> c(q);
  for (int i = 0; i < (q); i++) cin >> b[i] >> c[i];
  vector<ll> num(100005, 0);
  for (int i = 0; i < (n); i++) num[a[i]]++;
  ll sum = accumulate(a.begin(), a.end(), 0);
  for (int i = 0; i < (q); i++) {
    sum += (c[i] - b[i]) * num[b[i]];
    cout << sum << endl;
    num[c[i]] += num[b[i]];
    num[b[i]] = 0;
  }
  return 0;
}
