#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  long long int ans = 0;
  cin >> N;
  vector<int> A(N);
  int sum = 0;
  vector<int> num(100010, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    num[A[i]]++;
  }
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    sum += (C[i] - B[i]) * num[B[i]];
    num[C[i]] += num[B[i]];
    num[B[i]] = 0;
    cout << sum << endl;
  }
}
