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