#include<bits/stdc++.h>
//pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>   using orderedSet =tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define endl '\n'
//BFS+DFS
#define boundary(i,j) (i>=0 && i<n && j>=0 && j<m)
int X[]={-1,1,0,0};
int Y[]={0,0,1,-1};
int cnt[100003];
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        sum+=x;
        ++cnt[x];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        sum-=cnt[b]*b;
        sum+=cnt[b]*c;
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }

}


