N = int(input())
An = list(map(int,input().split()))
Q = int(input())
Bn = [0] * Q
Cn = [0] * Q
for c in range(Q):
    Bn[c], Cn[c] = map(int, input().split())

for count in range(Q):
    for index,an in enumerate(An):
        if an == Bn[count]:
           An[index] = Cn[count]
    print(sum(An))