#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    ans += a;
    mp[a]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    auto it = mp.find(b);
    long long num = it->second;
    ans -= it->first * num;
    ans += c * num;
    mp.erase(it->second);
    if (mp.find(c) == mp.end()) {
      mp.insert(make_pair(c, num));
    } else {
      mp[c] += num;
    }
    cout << ans << endl;
  }
  return 0;
}
