#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    inarr(n);
    ll sum=0;
    ll check[100005];
    memset(check,0,sizeof(check));
    for(int i=0;i<n;i++){
        in(temp);arr.push_back(temp);
        sum+=temp;
        check[temp]++;
    }
    in(q);
    while (q--){
        in(b);in(c);
        int t = check[b];
        sum = sum-t*b+t*c;
        check[c]+=t;
        cout<<sum<<endl;g
    }
    return 0;
}