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