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


for i in range(q):
    bc = list(map(int,input().split()))
    for j in range(n):
        if a[j] == bc[0]:
            a[j] = bc[1]
    print(sum(a))