#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
void solve(long long N, std::vector<long long> A, long long Q,
           std::vector<long long> B, std::vector<long long> C) {
  ll sum = 0;
  vector<ll> x(N + 1, 0);
  for (int i = 0; i < (N); ++i) {
    x[A[i]]++;
    sum += A[i];
  }
  for (int i = 0; i < (Q); ++i) {
    ll y = C[i] - B[i];
    sum += y * x[B[i]];
    std::cout << sum << std::endl;
    x[C[i]] += x[B[i]];
    x[B[i]] = 0;
  }
}
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &B[i]);
    scanf("%lld", &C[i]);
  }
  solve(N, std::move(A), Q, std::move(B), std::move(C));
  return 0;
}
