#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long int
#define inf 100000000000
#define MOD 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define for0(i, n) for (int i = 0; i < n; i++)
#define tc(t) int t; cin >> t; while (t--)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ps(x,y)         fixed<<setprecision(y)<<x
using namespace std;
using namespace __gnu_pbds;
int main()
{
	IOS
	int n;
	cin >> n;
	ll sum = 0;
	int freq[100005];
	int x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		freq[x]++;
		sum += x;
	}
	//cout << sum << endl;
	int q, b, c;
	cin >> q;
	while (q--)
	{
		cin >> b >> c;
		freq[c] += freq[b];
		sum -= freq[b] * b;
		sum += freq[b] * c;
		freq[b] = 0;
		cout << sum << endl;
	}
}