#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long arr[n];
  map<long long, long long> m;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
    sum += arr[i];
  }
  long long queries;
  cin >> queries;
  while (queries--) {
    long long b, c;
    cin >> b >> c;
    if (m.find(b) == m.end()) {
      cout << sum << "\n";
    } else {
      sum = sum - m[b] * b + m[b] * c;
      long long temp = m[b];
      m.erase(b);
      m[c] = temp;
      cout << sum << "\n";
    }
  }
  return 0;
}
