#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, a[100000], q, b[100000], c[100000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  vector<int> cnt(100001, 0);
  for (int i = 0; i < n; i++) cnt[a[i]]++;
  ll sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  for (int i = 0; i < q; i++) {
    sum -= b[i] * cnt[b[i]];
    sum += c[i] * cnt[b[i]];
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
