n = int(input())
a = input().split()
a = [int(x) for x in a]
q = int(input())
for i in range(q):
    bc = input().split()
    bc = [int(x) for x in bc]
    for l in range(len(a)):
        if a[l] == bc[0]:
            a[l] = bc[1]
    print(sum(a))