n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
    B, C = map(int, input().split())
    newA = a
    for i in a:
        if B in newA:
            newA[a.index(B)] = C
    print(sum(newA))