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