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

for i in range(q):
    b,c = map(int,input().split())
    indexes = [i for i, x in enumerate(a_li) if x == b]
    for i in indexes:
        a_li[i] = c
    print(sum(a_li))