#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){int i,k,q,n,ans=0,b,c;
map<int,int>mp;
cin>>n;
for(i=0;i<n;i++){
    cin>>k;
    ans+=k;
    mp[k]++;
}
cin>>q;
while(q--){
    cin>>b>>c;
    k=mp[b];
    ans+=k*(c-b);
    mp[b]=0;
    mp[c]+=k;
    cout<<ans<<"\n";
}
    return 0;
}