#include <bits/stdc++.h>
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 i = 0; i < Q; ++i) {
    cin >> B[i] >> C[i];
  }
  long long sum = 0;
  vector<int> cnt(10005, 0);
  for (int i = 0; i < N; ++i) {
    cnt[A[i]]++;
    sum += A[i];
  }
  for (int i = 0; i < Q; ++i) {
    int old_num = cnt[B[i]];
    long long minus = (long long)B[i] * (long long)old_num;
    long long plus = (long long)C[i] * (long long)old_num;
    cnt[C[i]] += old_num;
    sum = sum - minus + plus;
    cout << sum << endl;
  }
}
