#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ll n,sum=0;
    cin>>n;
    ll a[n+2];
    vector<vector<ll>>vp(100005,vector<int>());
    for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];vp[a[i]].push_back(a[i]);}
    ll k;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        ll x,y,d;
        cin>>x>>y;
        for(ll j=0;j<vp[x].size();j++)
        {
            //cout<<a[x]<<endl;
            sum-=vp[x][j];
            sum+=y;
            //a[x]=y;
            vp[y].push_back(y);
        }
        //for(auto k:vp[2])cout<<k<<" ";
        //for(int i=0;i<5;i++)
           // for(int j=0;j<4;j++)cout<<vp[i][j]<<" \n"[j==3];
        vp[x].clear();
        cout<<sum<<endl;
    }

}
