#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A.at(i);
  int q;
  cin >> q;
  vector<long long> ans(q + 1);
  for (int i = 0; i < n; i++) ans.at(0) += A.at(i);
  map<int, int> mp;
  for (int i = 0; i < n; i++) mp[A[i]]++;
  vector<int> B(q), C(q);
  for (int i = 0; i < q; i++) cin >> B.at(i) >> C.at(i);
  for (int i = 0; i < q; i++) {
    ans.at(i + 1) = ans.at(i) - mp[B.at(i)] * B.at(i) + mp[B.at(i)] * C.at(i);
    cout << ans.at(i + 1) << endl;
    mp[C.at(i)] += mp[B.at(i)];
    mp[B.at(i)] = 0;
  }
}
