#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<unsigned long long int, unsigned long long int> A;
  unsigned long long int sum = 0;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    ++A[t];
    sum += t;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    unsigned long long int B, C;
    cin >> B >> C;
    for (auto it = A.begin(); it != A.end();) {
      if (it->first == B) {
        unsigned long long int t = it->second;
        it = A.erase(it);
        A[C] += t;
        sum = sum - B * t + C * t;
      } else {
        it++;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
