#include<cstdio>
#include<iostream>
using namespace std;
long long n,q,a[100001],sum;
int tm[100001];
int main()
{
    while(~scanf("%lld",&n))
    {
        sum=0;
        for(int i=0;i<n;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            tm[a[i]]++;
        }
        scanf("%lld",&q);
        ll b,c;
        for(int i=0;i<q;++i)
        {
            scanf("%lld %lld",&b,&c);
            sum+=(c-b)*tm[b];
            tm[c]+=tm[b];
            tm[b]=0;
            printf("%lld\n",sum);
        }
    }
    return 0;
}