import collections

n = int(input())

a = list(map(int,input().split()))

q = int(input())

num_dict = dict(collections.Counter(a))
num_dict = {key : key * value for key, value in num_dict.items()}

for _ in range(q):
    b, c = map(int,input().split())

    num_dict[c] = int((c * num_dict.get(b, default=0) / b) + num_dict.get(c, default=0))

    if num_dict.get(b, default=0) != 0:
        del(num_dict[b])

    print(sum(num_dict.values()))