#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  long long Q;
  cin >> Q;
  vector<long long> B(Q), C(Q);
  for (int i = 0; i < (Q); i++) cin >> B[i] >> C[i];
  map<long long, long long> d;
  for (int i = 0; i < (N); i++) {
    d[A[i]]++;
  }
  for (int i = 0; i < (Q); i++) {
    d[C[i]] += d[B[i]];
    d[B[i]] = 0;
    long long ans = 0;
    for (auto x : d) {
      ans += x.first * x.second;
    }
    cout << ans << endl;
  }
}
