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


for q in range(Q):
    b, c = map(int, input().split())
    for n in range(N):
        if b == A[n]:
            A[n] = c
    print(sum(A))