#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long int N,Q,B,C,sum=0;
    cin>>N;

    long int arr[N]={},freq[100001]={};

    for(long int i=0;i<N;i++){
        cin>>arr[i];
        freq[arr[i]]++;
        sum+=arr[i];
    }

    cin>>Q;
    for(long int i=0;i<Q;i++){
        cin>>B>>C;
        sum-=(freq[B]*B);//cout<<freq[B]<<" before\n";
        sum+=(freq[B]*C);
        cout<<sum<<"\n";
        freq[C]+=freq[B];
    }


    return 0;
}
