#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()

#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................
ll first(ll arr[], ll low, ll high, ll x, ll n) 
{ 
    if (high >= low) { 
        ll mid = low + (high - low) / 2; 
        if ((mid == 0 || x > arr[mid - 1]) && arr[mid] == x) 
            return mid; 
        else if (x > arr[mid]) 
            return first(arr, (mid + 1), high, x, n); 
        else
            return first(arr, low, (mid - 1), x, n); 
    } 
    return -1; 
} 
  
/* if x is present in arr[] then returns the index of 
   LAST occurrence of x in arr[0..n-1], otherwise 
   returns -1 */
ll last(ll arr[], ll low, ll high, ll x, ll n) 
{ 
    if (high >= low) { 
        ll mid = low + (high - low) / 2; 
        if ((mid == n - 1 || x < arr[mid + 1]) && arr[mid] == x) 
            return mid; 
        else if (x < arr[mid]) 
            return last(arr, low, (mid - 1), x, n); 
        else
            return last(arr, (mid + 1), high, x, n); 
    } 
    return -1; 
} 
  

int main()
{   
    
    fast
    ll n;
    cin>>n;
    ll vec[n];
    ll sum=0;
    unordered_map<ll,ll>mp;
    rep(i,n){
        cin>>vec[i];
        sum+=vec[i];
        mp[vec[i]]++;
    }
    //sort(vec,vec+n);
    ll q;
    ll b,c;
    cin>>q;
    while(q--){
        cin>>b>>c;
        //ll l=first(vec,0,n-1,b,n);
        //ll r=last(vec,0,n-1,b,n);
        //ll k=r-l+1;
        sum=sum-(b*mp[b]);
        sum=sum+c*mp[b];
        mp[c]=mp[c]+mp[b];
        mp[b]=0;
        cout<<sum<<nl;
    }
 
   
   
    return 0;
}

Measured memory_bytes: 7908