N=int(input())
li = list(map(int,input().split()))
Q=int(input())

for i in range(Q):#O(N**2)⇒TLE
    B,C = map(int,input().split())
    for j in range(N):
        if li[int(j)] == B:
            li[int(j)]=C
    print(sum(li))