n = int(input())
a = [int(i) for i in input().split(" ")]
q = int(input())

operations = [

]

for i in range(q):
    temp = input().split(" ")
    operations.append((int(temp[0]), int(temp[1])))

for op in operations:
    target, goto = op

    for i in range(len(a)):
        if a[i] == target:
            a[i] = goto

    print(sum(a))