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