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