#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  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];
    mp[v[i]]++;
    sum += v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= ((long long int)mp[b] * b);
    sum += ((long long int)mp[b] * c);
    mp[b] = 0;
    mp[c] += mp[b];
    cout << sum << endl;
  }
  return 0;
}
