#include <bits/stdc++.h>
using LL = long long;
using namespace std;
int main() {
  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(Q), C(Q);
  for (int q = 0; q < Q; q++) {
    cin >> B[q] >> C[q];
  }
  map<int, int> M;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    M[A[i]]++;
    sum += A[i];
  }
  for (int q = 0; q < Q; q++) {
    int temp = M[B[q]];
    sum = sum + temp * (C[q] - B[q]);
    M[B[q]] = 0;
    M[C[q]] += temp;
    cout << sum << endl;
  }
  return 0;
}
