#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
typedef vector<pair<ll,ll> > vpii;
typedef vector<ll> vi;
const ll INF=1e17+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)cin>>a[i];
}
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);}
bool isprime(ll n){
    if(n==1)return false;
    if(n==2 || n==3)return true;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}
//ll x[100001]={0};
ll a[200001]={0};
//ll b[200001]={0};
//bool c[100000001]={0};
//vector<pair<ll,ll> > adj[100001];
//vector<ll> adj[100001];
//vpii edges;
//bool visited[100001]={0};
//bool color[100001]={0};
//ll dist[100001]={0};
ll binary_expon(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2)res=(res*a)%INF;
        a=(a*a)%INF;
        b/=2;
    }
    return res%INF;
}

void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)res*=i;
    return res;
}

double distance(ll x1,ll y1,ll x2,ll y2){
    return (sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

/*void tree_dfs(ll curr,ll prev){
    for(auto u:adj[curr]){
        if(u!=prev){
            tree_dfs(u,curr)+1;
        }
    }
}*/

/*void dfs(ll x,ll y,ll px,ll py,char color){
    if(x<0 || y<0 || x>=n || y>=m)return;
    if(grid[x][y]!=color)return;

    if(visited[x][y]){
        f=true;
        return;
    }
    visited[x][y]=true;

    if(px!=(x+1) || py!=y)
        dfs(x+1,y,x,y,color);
    if(px!=(x-1) || py!=y)
        dfs(x-1,y,x,y,color);
    if(px!=(x) || py!=y+1)
        dfs(x,y+1,x,y,color);
    if(px!=(x) || py!=y-1)
        dfs(x,y-1,x,y,color);
}*/

/*bool isVowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}*/
//ll grid[1001][1001]={0};

/*void dfs(ll s,bool colr){
    if(visited[s])return;
    visited[s]=true;
    color[s]=colr;
    for(auto u:adj[s]){
        dfs(u,!colr);
    }
}*/
//set<pair<ll,ll> >edges;
/*vector<ll> z(string s) {
    ll n=s.length();
    vector<ll> z(n);
    ll x=0,y=0;
    for(ll i=1;i<n;i++) {
        z[i]=max(0ll,min(z[i-x],y-i+1));
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]){
            x = i; y = i+z[i]; z[i]++;
        }
     }
    return z;
}*/

void solve(){
    ll n;cin>>n;
    map<ll,ll> m;
    ll sum=0;

    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        m[a[i]]++;
    }

    /*for(auto x:m){
        cout<<x.first<<" "<<x.second<<endl;
    }*/

    ll q;cin>>q;

    for(ll i=0;i<q;i++){
        ll b,c;cin>>b>>c;
        map<ll,ll>::iterator it=m.find(b);

        if(it==m.end()){
            cout<<sum<<endl;
            continue;
        }

        sum-=b*(it->second);
        sum+=c*(it->second);
        if(m.find(c)==m.end()){
            m[c]=it->second;
        }
        else{
            m[c]+=it->second;
        }
        m[b]=0;
        //m[c]+=it->second;

        cout<<sum<<endl;
        //cout<<endl;
        /*for(auto x:m){
            cout<<x.first<<" "<<x.second<<endl;
        }
        cout<<endl;*/
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //sieve(10000001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Measured memory_bytes: 9492