// Author: pankaj_m05 
// Problem: d 
// Created: 21.06.2020 18:28:02

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;

void testcase() {
	int n;
	cin >> n;
	int a[n], 
	ll sum = 0;
	unordered_map<int, int> freq;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
		freq[a[i]]++;		
	}
	// cout << sum << '\n';
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {	
		int b, c;
		cin >> b >> c;
        freq[c] += freq[b];
        sum = sum + freq[b] * (c - b);
        freq[b] = 0;
        cout << sum << '\n';	
	}
}

int main(void) { 
	fast
	int t = 1; 
	// cin >> t;
	while (t--) {
		testcase();
	}
	return 0;
}                                          