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