//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

	
	clock_t startTime=clock();

	ll n,sum=0;
	cin>>n;
    ll arr[n];
    map <ll,ll> mp;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    cin>>k;
    for(i=0;i<k;i++)
    {
        cin>>a>>b;

        sum-=a*mp[a];
        sum+=b*mp[a];
        mp[b]+=mp[a];
        mp[a]=0;
        cout<<sum<<endl;
    }

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...