#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  for (long long i = 0; i < q; i++) cin >> b[i] >> c[i];
  vector<long long> s(10001, 0);
  for (long long i = 0; i < n; i++) {
    s[a[i]]++;
  }
  for (long long i = 0; i < q; i++) {
    sum -= s[b[i]] * b[i];
    sum += s[b[i]] * c[i];
    s[c[i]] += s[b[i]];
    s[b[i]] = 0ll;
    cout << sum << "\n";
  }
}
