#include <bits/stdc++.h>
using namespace std;
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
int32_t main() {
  int n, q;
  cin >> n;
  map<int, int> mp;
  int arr[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    mp[arr[i]]++;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (mp[b] == 0) {
      cout << sum << "\n";
      continue;
    } else {
      sum -= b * mp[b];
      sum += c * mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
      cout << sum << "\n";
    }
  }
  return 0;
}
