N =int(input())
A = list(map(int,input().split()))
Q = int(input())
X = []

for i in range(Q):
    sum = 0
    ope = list(map(int,input().split()))
    B = [i for i, x in enumerate(A) if x == ope[0]]
    for j in B:
        A[j] = ope[1]

    for j in A:
        sum += j
    X.append(sum)

for i in X:
    print(i)
