#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto& x : a) cin >> x;
  map<long long, long long> mp;
  long long sm = 0;
  for (long long i = 0; i < n; i++) {
    mp[a[i]]++;
    sm += a[i];
  }
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long b, c;
    cin >> b >> c;
    if (mp.count(b) == 0) {
      cout << sm << '\n';
      return;
    }
    long long cur = mp[b];
    mp[c] += cur;
    sm -= cur * b;
    sm += cur * c;
    cout << sm << '\n';
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
