#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmax(T &ans, T t) {
  if (t > ans) ans = t;
}
template <class T>
inline void chmin(T &ans, T t) {
  if (t < ans) ans = t;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  map<int, int> mp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    int cnt = mp[b];
    sum -= cnt * b;
    sum += cnt * c;
    mp[b] = 0;
    mp[c] += cnt;
    cout << sum << endl;
  }
}
