#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	int temp, numbers[100001] = {0};
	long long sum = 0;
	while(N-- > 0){
        cin >> temp;
        numbers[temp]++;
        sum += temp;
	}
    int Q, B, C;
    cin >> Q;
    while(Q-- > 0){
        cin >> B >> C;
        sum += (C - B) * numbers[B];
        numbers[C] += numbers[B];
        numbers[B] = 0;
        cout << sum << endl;
    }
	return 0;
}
