#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
signed main(void) {
  int n, q;
  long long sum;
  cin >> n;
  vector<int> vec(n);
  map<int, int> mp;
  sum = 0;
  for (int i = 0; i < (n); i++) {
    cin >> vec[i];
    mp[vec[i]]++;
    sum += vec[i];
  }
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
