#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> P(100010, 0);
  for (long long i = 0; i < N; ++i) {
    int A;
    cin >> A;
    P[A]++;
  }
  long long sum = 0;
  for (long long i = 0; i < P.size(); ++i) {
    sum += i * P[i];
  }
  int Q;
  cin >> Q;
  vector<long long> S(Q);
  for (long long i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    sum -= (long long)(B * P[B]);
    sum += (long long)(C * P[B]);
    P[C] += P[B];
    P[B] = 0;
    S[i] = sum;
  }
  for (auto s : S) cout << s << endl;
}
