#include <bits/stdc++.h>
using namespace std;
void zaroorat() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  zaroorat();
  long long n;
  cin >> n;
  long long arr[n];
  long long hash[100000];
  long long su = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    hash[arr[i]]++;
    su += arr[i];
  }
  long long q;
  cin >> q;
  while (q > 0) {
    long long a, b;
    cin >> a >> b;
    su += b * hash[a] - a * hash[a];
    hash[b] += hash[a];
    hash[a] = 0;
    cout << su << endl;
    q--;
  }
  return 0;
}
