#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, const T &b) {
  if (b > a) a = b;
}
const int inf = 1e9 + 10;
const int maxn = 1e5 + 10;
int cnt[maxn], n, q;
long long ans = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (int i = 0; i < maxn; i++)
    ans += long long(long long(cnt[i]) * long long(i));
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    ans -= long long(long long(cnt[a] * a));
    ans += long long(long long(cnt[a] * b));
    cnt[b] += cnt[a];
    cout << ans << endl;
  }
  return 0;
}
