#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 3];
  map<int, int> m;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    m[arr[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int n1, n2;
    cin >> n1 >> n2;
    if (m.find(n1) != m.end()) {
      m[n2] = m[n2] + m[n1];
      sum = sum + (m[n1] * n2) - (m[n1] * n1);
      m.erase(n1);
    }
    cout << sum << endl;
  }
  return 0;
}
