#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, T2 y) {
  if (x < y) x = y;
}
ostream &operator<<(ostream &a, const vector<long long> &b) {
  for (auto k : b) cout << k << ' ';
  return a;
}
const long long MOD = 1000000007;
const long long INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const long long MX = 200010;
const double EPS = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long cnt[MX];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    cnt[x]++;
    sum += x;
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    sum -= b * cnt[b];
    sum -= c * cnt[c];
    cnt[c] += cnt[b];
    sum += cnt[c] * c;
    cout << sum << '\n';
  }
}
