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