#include <bits/stdc++.h>
using namespace std;
int existe[100001];
int main() {
  int n;
  cin >> n;
  int arr[n];
  int sum = 0;
  for (int index = 0; index < n; index++) {
    cin >> arr[index];
    existe[arr[index]]++;
    sum += arr[index];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= (existe[b] * b);
    sum += (existe[b] * c);
    existe[c] += existe[b];
    existe[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
