// Original C++ solution (slower):
#include <iostream>





#define endl '\n'

#define pi acos(-1)

#define euler_e 2.71828

#define pii pair<int,int>

#define pb push_back

#define all(a) a.begin(),a.end()

#define ll long long

#define ull unsigned long long

#define io freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

void mycode();

const ll int mod=998244353;

ll int ceil(ll int a,ll int b){return (a+b-1)/b;}

ll int min(ll int a, ll int b){if(a>b)return b;else return a;}

bool bit_check(ll int a,int i){

  if((a & (1LL<<i)))return 1;

  return 0;

}

ll int bit_toggle(ll int a,int i){

  return (a^(1LL<<i));

}

ll int bit_sum(ll int a,int i){

  return a+(1LL<<i);

}

ll int bit_sub(ll int a,int i){

  return a-(1LL<<i);

}

ll int mod_power(ll int x,ll int y){//x^y%p

  ll int p=mod;

  ll int res = 1;

  x = x % p;

  while (y > 0) { 

    if (y & 1)res = (res*x) % p;

    y = y>>1;x = (x*x) % p;

  }

  return res;

}

ll int power_of(ll int a,int b){

  if(a==0)return -1;

  return 1+power_of(a/b,b);

}

ll int power(ll int a, ll int b) {

	if(a==1)return 1;

    ll int res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a;

        a = a * a;

        b >>= 1;

    }

    return res;

}

//__int128

int main(){

	boost;

	//io;

	//auto start = chrono::high_resolution_clock::now();

	mycode();

	//auto end = chrono::high_resolution_clock::now();cerr << "\nExecution time: "<< chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms" << endl;

	return 0;

}

#include<map>

void mycode(){

	int t,k;

	cin>>t;

	ll int sum=0;

	map<int,int>mp;

	for(int i=0;i<t;i++){cin>>k;mp[k]++;sum+=k;}

	int q,a,b;

	cin>>q;

	while(q--){

		cin>>a>>b;

		sum+=-mp[a]*a+mp[a]*b;

		cout<<sum<<endl;

		mp[b]+=mp[a];

		mp.erase(a);

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std; 

typedef long long LL;

const int MAXN=1E5+10;

int f[MAXN],sum[MAXN],tong[MAXN],a[MAXN];

long long sumans;



int main() {

	int N,K;

	scanf("%d",&N);

	sumans=0;

	for(int i=1;i<=N;++i) {

		scanf("%d",&a[i]);

		sumans+=a[i];

		tong[a[i]]+=1;

	}

	scanf("%d",&K);

	for(int i=1;i<=K;++i) {

		int b,c;scanf("%d%d",&b,&c);

		sumans-=1ll*tong[b]*b;

		sumans+=1ll*tong[b]*c;

		

		tong[c]+=tong[b];

		tong[b]=0;

		

		printf("%lld\n",sumans);

	}

	

	return 0;

} 

// Fastest known solution for this problem:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#include <string>

const int mxN=1e5;

const int maxN=5e3;

#define ld long double

#define pb push_back

#define mp make_pair

#define ins insert

#define vi vector<int>



int main()

{

    int n;

    cin >> n;

    int cnt[100000]={};

    ll s=0;

    for(int i=0;i<n;i++)

    {

        int x;

        cin >> x;

        cnt[x-1]++;

        s+=x;

    }

    int q;

    cin >> q;

    while(q--)

    {

        int b,c;

        cin >> b >> c;

        s+=cnt[b-1]*(c-b);

        cnt[c-1]+=cnt[b-1];

        cnt[b-1]=0;

        cout << s << "\n";

    }

}