#Replacing
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
asum = A.sum()
for i in range(Q):
    B, C = list(map(int, input().split()))
    CC = A==B
    NC = CC==False
    A = A*(NC) + C*CC
    asum += np.count_nonzero(CC) *(C-B)
    print(asum)
    # print(A.sum())