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