#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  map<int, int> mp;
  ll sum = 0;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    sum += A;
    mp[A]++;
  }
  int Q;
  cin >> Q;
  vi B(Q), C(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; ++i) {
    sum -= B[i] * mp[B[i]];
    sum += C[i] * mp[B[i]];
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
