#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int anums[10005] = {};
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    anums[a]++;
    sum += a;
  }
  int Q;
  cin >> Q;
  vector<long long> bs(Q);
  vector<long long> cs(Q);
  for (int i = 0; i < Q; i++) {
    cin >> bs.at(i) >> cs.at(i);
  }
  for (int i = 0; i < Q; i++) {
    sum = sum + (cs[i] - bs[i]) * anums[bs[i]];
    anums[cs[i]] = anums[bs[i]];
    anums[bs[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
