#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
void out(T a) {
  cout << a << endl;
}
template <class T>
void die(T a) {
  cout << a << endl;
  exit(0);
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
long long inv[200005], fac[200005], finv[200005];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 200005; i++) {
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    fac[i] = fac[i - 1] * (long long)i % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
  return;
}
long long comb(int a, int b) {
  if (a < b) return 0;
  return fac[a] * (finv[b] * finv[a - b] % 1000000007) % 1000000007;
}
long long beki(int a, int n) {
  if (n == 0) return 1;
  long long ans = beki(a, n / 2);
  ans = ans * ans;
  if (n % 2 == 1) ans = ans * a;
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N;
  vector<long long> A(N), B(Q), C(Q);
  for (long long i = 0; i < A.size(); ++i) cin >> A[i];
  ;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) cin >> B[i] >> C[i];
  vector<long long> cnt(100005, 0);
  for (int i = 0; i < (int)(N); i++) cnt[A[i]]++;
  vector<long long> sum(100005, 0);
  for (int i = 0; i < (int)(100005); i++) sum[i] = cnt[i] * i;
  long long ans = accumulate(sum.begin(), sum.end(), 0LL);
  for (int i = 0; i < (int)(Q); i++) {
    cnt[C[i]] += cnt[B[i]];
    ans += cnt[B[i]] * (C[i] - B[i]);
    cnt[B[i]] = 0;
    out(ans);
  }
}
