#include <bits/stdc++.h>
using namespace std;
void ans(map<int64_t, int64_t> &mp) {
  int64_t sum = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    sum += (it->first) * (it->second);
  }
  cout << sum << endl;
}
int main() {
  int64_t N, Q, a, b, c;
  cin >> N;
  map<int64_t, int64_t> mp;
  for (int i = 0; i < N; i++) {
    cin >> a;
    mp[a]++;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    int64_t n = mp[b];
    mp.erase(b);
    mp[c] += n;
    ans(mp);
  }
}
