#include <bits/stdc++.h>

#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(var,start,end) for(int var=start; var<end; var++)
#define repr(var,start,end) for(int var=start; var>=end; var--)
#define repi(var,start,end) for(int var=start; var<=end; var++)
#define debg(var) cerr<<#var<<" : "<<var<<" "
#define pb push_back
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

void solve() {
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n)
        cin>>a[i];
    map<int,int> m;
    rep(i,0,n) {
        m[a[i]]++;
    }4
    int q;
    cin>>q;
    ull sum = accumulate(a,a+n,0);
    while(q--) {
        int b,c;
        cin>>b>>c;
        int k = m[b];
        sum-=(b*k);
        m.erase(b);
        m[c] += k;
        sum+=(c*k);
        cout<<sum<<'\n';
    }    
}


int main() {
    fastio
    int t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}