#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  ll total = 0;
  map<int, int> mp;
  vector<int> A(N);
  for (int i = 0; i <= N - 1; ++i) {
    cin >> A[i];
    total += A[i];
    mp[A[i]]++;
  }
  int Q;
  cin >> Q;
  int b, c;
  queue<ll> answers;
  for (int i = 0; i <= Q - 1; ++i) {
    cin >> b >> c;
    total -= b * mp[b];
    total += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    answers.push(total);
  }
  while (!answers.empty()) {
    cout << answers.front() << endl;
    answers.pop();
  }
  return 0;
}
