#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<int, int> mp;
  int n, q, now, b, c;
  ll sum = 0;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> now;
    mp[now]++;
    sum += now;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    if (!mp[b]) {
      cout << sum << endl;
      continue;
    }
    sum -= mp[b] * b;
    sum += mp[b] * c;
    mp[c] += mp[b];
    mp[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
