#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main() {
    ll n,b,c,t,s=0,i,l; cin>>n; ll a[10001];
    map<ll,ll>m;
    for(i=1;i<=n;i++) {cin>>l; m[l]++; s+=l;}
    cin>>t; 
    while(t--)
    {
        cin>>b>>c; s+=(m[b]*(c-b)); 
        m[c]+=m[b]; m.erase(m.find(b));
        cout<<s<<endl;
    }
    return 0;
}