#include <bits/stdc++.h>
using namespace std;
const long long MOD = round(1e9 + 7);
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  int Q;
  cin >> Q;
  vector<long long> B(N), C(N);
  for (long long i = 0; i < Q; i++) cin >> B[i] >> C[i];
  map<int, long long> mp;
  long long sum = 0;
  for (long long i = 0; i < N; i++) mp[A[i]]++;
  for (long long i = 0; i < N; i++) sum += A[i];
  queue<long long> ans;
  for (long long i = 0; i < Q; i++) {
    sum += (C[i] * mp[B[i]] - B[i] * mp[B[i]]);
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    ans.push(sum);
  }
  while (!ans.empty()) {
    cout << ans.front() << "\n";
    ans.pop();
  }
  return 0;
}
