#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define endl "\n"
#define pii tuple<ll,ll,ll>
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const ll N=1005;
const ll INF=LLONG_MAX;
void amfetamin()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
int main()
{
amfetamin();
int n,q;
cin>>n;
int freq[100001];
ll sol=0;
for (int i=1; i<=100000; i++)
    freq[i]=0;
for (int i=0; i<n; i++)
{
    int a;
    cin>>a;
    sol+=a;
    freq[a]++;
}
cin>>q;
for (int i=0; i<q; i++)
{
    int b,c;
    cin>>b>>c;
    int cur=freq[b];
    freq[b]=0;
    sol-=cur*b;
    sol+=cur*c;
    freq[c]+=cur;
    cout<<sol<<endl;
}

}
