#include <stdio.h>
int n, q;
long long s, a, b, c;
long long x[100001];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a);
		x[a]++;
		s += a;
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld", &b, &c);
		s += x[b] * (c - b);
		x[c] += x[b];
		x[b] = 0;
		printf("%lld\n", s);
	}
}