N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = []
C = []
S = []
for i in range(Q):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)
for j in range(Q):
    X = []
    for x in range(len(A)):
        if A[x] == B[j]:
            X.append(x)
            A[x] = ''
    for k in range(len(X)):
        A[X[k]] = C[j]
    s = sum(A)
    S.append(s)
for y in range(len(S)):
    print(S[y])