#include"pch.h"
#include<iostream>

using namespace std;

void trans(int a[], int b, int c, int n) {
	for (int i = 0; i < n; i++) {
		if (a[i] == b) {
			a[i] = c;
		}
	}
}
int main() {
	int n;
	int a[100], b[100], c[100];
	int q;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> b[i] >> c[i];
	}

	int sum = 0;

	for (int i = 0; i < q; i++) {
		trans(a, b[i], c[i], n);
		for (int i = 0; i < n; i++) {
			sum = sum + a[i];
		}
		cout << sum << "\n";
		sum = 0;
	}
	
}