#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double Pi = acos(-1);
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  int a;
  map<int, int> mp;
  for (int i = 0; i < (n); ++i) {
    cin >> a;
    mp[a]++;
  }
  int q;
  cin >> q;
  int bb[q], cc[q];
  for (int i = 0; i < (q); ++i) cin >> bb[i] >> cc[i];
  mp[cc[0]] += mp[bb[0]];
  mp[bb[0]] = 0;
  ll ans = 0;
  for (auto iter = mp.begin(); iter != mp.end(); iter++) {
    ans += iter->first * iter->second;
  }
  cout << ans << endl;
  for (int i = 1; i <= (q - 1); ++i) {
    int b = bb[i], c = cc[i];
    int tmp = mp[b];
    ans -= b * tmp;
    ans += c * tmp;
    mp[b] = 0;
    mp[c] += tmp;
    cout << ans << endl;
  }
  return 0;
}
