#include <iostream>
using namespace std;
#define ll long long
const int N = 1e5+507;
ll n,i,sum,q,b,c,a[N],f[N];
int main ()
{
    cin>>n;
    for (i=1;i<=n;++i)
        cin>>a[i],f[a[i]]++,sum+=a[i];
    cin>>q;
    for (i=1;i<=q;++i)
    {
        cin>>b>>c;
        sum-=f[b]*b;
        sum+=f[b]*c;
        f[c]+=f[b];
        f[b]=0;
        cout<<sum<<"\n";
    }
}

