#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
ll dat[100100] = {0};
int main() {
  ll n, q;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    dat[a[i]]++;
  }
  cin >> q;
  vector<ll> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) {
    cin >> b[i] >> c[i];
  }
  ll sum = 0;
  for (int j = 0; j < (int)(100000); j++) {
    sum += dat[j] * j;
  }
  for (int i = 0; i < (int)(q); i++) {
    sum -= dat[b[i]] * b[i];
    sum += dat[b[i]] * c[i];
    cout << sum << endl;
    dat[c[i]] += dat[b[i]];
    dat[b[i]] = 0;
  }
}
