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