#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, a, b;
  long long sum = 0;
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    cin >> a;
    mp[a]++;
    sum += a;
  }
  long long q;
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    cin >> a >> b;
    long long x = mp[a];
    if (x > 0) {
      sum -= (x * a);
      mp[a] = 0;
      mp[b] += x;
      sum += (mp[b] * b);
    }
    cout << sum << endl;
  }
}
