#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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;
}
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N + 1);
  ll ans = 0;
  map<int, int> cnt;
  for (int i = 1; i <= (int)N; i++) {
    cin >> A[i];
    ans += A[i];
    cnt[A[i]]++;
  }
  cin >> Q;
  vector<int> B(N + 1);
  vector<int> C(N + 1);
  for (int i = 1; i <= (int)Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 1; i <= (int)Q; i++) {
    if (cnt[B[i]] != 0) {
      ans += (C[i] - B[i]) * cnt[B[i]];
      cnt[C[i]] += cnt[B[i]];
      cnt[B[i]] = 0;
      cout << ans << endl;
    } else {
      cout << ans << endl;
    }
  }
}
