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