#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  vector<ll> count(100001, 0);
  cin >> N;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    count[temp]++;
    sum += temp;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    sum += (C - B) * count[B];
    count[C] += count[B];
    count[B] - 0;
    cout << sum << endl;
  }
  return 0;
}
