#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
typedef long long LL;

int n, cnt[N], q;
LL ans;

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		int x;
		cin>>x;
		cnt[x]++;
		ans += x;
	}
	cin>>q;
	for(int i = 1; i <= q; i++) {
		int x, y;
		cin>>x>>y;
		ans += (y - x)*cnt[x]; 
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout<<ans<<endl;
	}
	return 0;
}