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

int main()
{
    ll N = 0;cin >> N;
    ll arr[N+1]={0};
    ll ans = 0;
   for(ll i = 1;i <= N; i++)
    {
        ll val = 0;cin >> val;
        arr[val]++;
        ans += val;
    }
    ll q = 0;cin >> q;
    for(ll i = 0;i < q; i++)
    {
        ll b = 0,c = 0;cin >> b >> c;
        ans += (c-b)*arr[b];
        arr[b]--;
        arr[c]++;
        cout << ans << endl;
        
    }
    
    return 0;
}