#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;cin >> n;
vector<ll>a(n);
vector<ll>b(1e5+10);
ll sum = 0;
for(int i = 0;i<n;i++){
    cin >> a[i];
    b[a[i]]++;
    sum += a[i];
}
int t;cin >> t;
while(t--){
    ll r;ll d;
    cin >> r >> d;
    sum += (d-r)*b[r];
    b[d] += b[r];
    b[r] = 0;
    cout << sum <<endl;
}
return 0;
}