N = int(input())
A = list(map(int, input().split()))
Q = int(input())
total=sum(A)
for i in range(Q):
    B, C = map(int, input().split())
    x=A.count(B)
    if x>0:
        for j in range(0,x):
            y=A.index(B)
            total=total-A[y]+C
            A[y]=C
    print(total)

