#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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long int cnt[100100];
void func(long long N, std::vector<long long> A, long long Q,
          std::vector<long long> B, std::vector<long long> C) {
  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    cnt[A[i]]++;
    sum += A[i];
  }
  for (int i = 0; i < Q; i++) {
    long long int fromC = cnt[B[i]];
    sum -= B[i] * fromC;
    sum += C[i] * fromC;
    cnt[C[i]] += fromC;
    cout << sum << endl;
  }
}
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]);
  }
  func(N, std::move(A), Q, std::move(B), std::move(C));
  return 0;
}
