#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n + 1];
  long long sum = 0;
  map<int, int> fr;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    fr[a[i]]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= fr[x] * x;
    sum += y * fr[x];
    fr[y] += fr[x];
    fr[x] = 0;
    cout << sum << '\n';
  }
  return 0;
}
