#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, Q;
    cin >> N;
    int A[100010]={0};
    for (int i=0; i<N; i++) {
        int a;
        cin >> a;
        A[a]++;
    }
    int sum=0;
    for (int i=0; i<N; i++) {
        sum+=i*A[i];
    }
    cin >> Q; 
    pair <int, int> B[Q];
    for (int i=0; i<Q; i++) cin >> B[i].first >> B[i].second;
    for (int i=0; i<Q; i++){
        if (C[B[i].first]){
            sum=sum+(B[i].second-B[i].first)*C[B[i].first];
            C[B[i].second]+=C[B[i].first];
            C[B[i].first]=0;
            cout << sum << endl; 
        }
        else cout << sum << endl;
    }
}
