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