#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N;
  vector<ll> A(N);
  vector<ll> cnt(100005);
  rep(i, N) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  ll sum = accumulate(all(A), 0LL);
  cin >> Q;
  vector<ll> B(Q), C(Q);
  rep(i, Q) cin >> B[i] >> C[i];
  rep(i, Q) {
    sum += cnt[B[i]] * (C[i] - B[i]);
    cnt[C[i]] += cnt[B[i]];
    cnt[B[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
