#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++) {
    int num = anums[bs.at(i)];
    sum = sum + ((cs.at(i) - bs.at(i)) * num);
    anums[cs.at(i)] += num;
    anums[bs.at(i)] = 0;
    cout << sum << endl;
  }
  return 0;
}
