#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int cnt[N];
void Suhaib_Sawalha() {
  int n, q;
  cin >> n;
  int a[n];
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  int bf, af;
  while (q--) {
    cin >> bf >> af;
    sum -= bf * cnt[bf];
    sum += af * cnt[bf];
    cnt[af] += cnt[bf];
    cnt[bf] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Suhaib_Sawalha();
  return 0;
}
