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