#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  long long sum = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
    if (mp.count(arr[i])) {
      mp[arr[i]]++;
    } else {
      mp[arr[i]] = 1;
    }
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    if (mp.count(b)) {
      int cnt = mp[b];
      mp[b] = 0;
      mp[c] += cnt;
      long long sub = cnt * b;
      long long add = cnt * c;
      sum -= sub;
      sum += add;
      cout << sum << '\n';
    } else {
      cout << sum << '\n';
    }
  }
  return 0;
}
