#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  int Q;
  cin >> Q;
  vector<int> B(N);
  vector<int> C(N);
  for (int i = 0; i < (Q); ++i) cin >> B[i] >> C[i];
  vector<int> num(100001);
  for (int i = 0; i < (N); ++i) {
    num[A[i]]++;
  }
  ll ans = accumulate(A.begin(), A.end(), 0);
  for (int i = 0; i < (Q); ++i) {
    ans += (C[i] - B[i]) * num[B[i]];
    num[C[i]] += num[B[i]];
    num[B[i]] = 0;
    cout << ans << endl;
  }
}
