#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ll sum = 0;
  map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    cnt[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    sum -= cnt[a] * a;
    sum += cnt[a] * b;
    cout << sum << '\n';
    cnt[b] += cnt[a];
    cnt[a] = 0;
  }
  return 0;
}
