import numpy as np
 
N = int(input())

A = list(map(int, input().split()))

npA = np.array(A)

Q = int(input())

Anslist = [0] * Q

for i in range(Q):

    b, c = map(int, input().split())

    A_replace = np.where(npA == b, c, npA)

    npA = A_replace
    
    Anslist[i] += sum(A_replace)

for k in range(Q):

    print(Anslist[k])
