#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int mp[110000] = {0};
  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 i = 0; i < Q; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) continue;
    sum -= a * mp[a];
    sum += b * mp[a];
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << '\n';
  }
  return 0;
}
