#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  const int MAX = 100010;
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(MAX);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ++cnt[a[i]];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, d;
    cin >> b >> d;
    sum -= cnt[b] * b;
    sum += cnt[b] * d;
    cnt[d] += cnt[b];
    cnt[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
