#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  map<int, int> mp;
  long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
    sum += arr[i];
  }
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    if (mp.find(x) != mp.end()) {
      sum = sum - (mp[x] * x) + (mp[x] * y);
      mp[y] = mp[y] + mp[x];
      mp[x] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
