#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &it : a) cin >> it;
    int q;
    cin >> q;
    int b, c;
    long long int sum = accumulate(a.begin(), a.end(), 0);
    unordered_map<int, int> mp;
    for (auto i : a) mp[i]++;
    for (int i = 0; i < (int)q; i++) {
      cin >> b >> c;
      if (mp.count(b)) {
        sum -= 1LL * mp[b] * b;
        sum += 1LL * mp[b] * c;
        mp[c] += mp[b];
        mp[b] -= mp[b];
      }
      cout << (long long int)sum << '\n';
    }
  }
  return 0;
}
