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()))
    for j in range(N):
        if A[j] == ope[0]:
            A[j] = ope[1]
        sum += A[j]
    X.append(sum)

for i in X:
    print(i)
