#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  int A;
  long long total = 0;
  int cnt[100005] = {0};
  cin >> N;
  for (int i = (0); i < (N); ++i) {
    cin >> A;
    cnt[A]++;
    total += A;
  }
  cin >> Q;
  int B, C;
  for (int i = (0); i < (Q); ++i) {
    cin >> B >> C;
    total += cnt[B] * (C - B);
    cnt[C] += B;
    cnt[B] = 0;
    cout << (total) << '\n';
  }
  return 0;
}
