#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  long long N;
  cin >> N;
  vector<long long> A(N);
  vector<long long> counter(100001, 0);
  vector<long long> num(100001);
  for (int i = 1; i <= 100000; i++) {
    num.at(i) = i;
  }
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    counter.at(A.at(i))++;
  }
  long long Q;
  cin >> Q;
  while (Q--) {
    long long B, C;
    cin >> B >> C;
    sum -= counter.at(B) * num.at(B);
    num.at(B) = C;
    sum += counter.at(B) * num.at(B);
    counter.at(C) += counter.at(B);
    counter.at(B) = 0;
    cout << sum << "\n";
  }
}
