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