#include <bits/stdc++.h>
using namespace std;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  long long ans = 0;
  map<int, int> mp;
  for (int(i) = 0; (i) < (N); (i)++) {
    cin >> A[i];
    mp[A[i]]++;
    ans += A[i];
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int(i) = 0; (i) < (Q); (i)++) {
    cin >> B[i] >> C[i];
    ans += (C[i] - B[i]) * mp[B[i]];
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
