#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<long long, long long> mp;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    mp[A]++;
    ans += A;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    long long n = 0;
    auto ite = mp.begin();
    for (ite; ite != mp.end(); ite++) {
      if (ite->first == B) break;
    }
    if (ite != mp.end()) {
      ans += (C - B) * ite->second;
      mp[C] += ite->second;
      ite->second = 0;
    }
    cout << ans << endl;
  }
}
