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

int a[100001];


int64_t main(){
    int n,q,b,c;
    unsigned long long int sum=0;
    cin>>n;
    int temp;
    for(int i=0;i<n;++i){
        cin>>temp;
        sum=sum+temp;
        a[temp]++;
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        int count=a[b];
        sum = sum-(count*b);
        a[b]=0;
        a[c]=a[c]+count;
        sum = sum+(count*c);
        cout<<sum<<endl;
    }
    
    
    return 0;
}