N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    BTemp,CTemp = map(int, input().split())
    B.append(BTemp)
    C.append(CTemp)
for BTemp,CTemp in zip(B,C):
    ATemp = []
    try:
        while True:
            A[A.index(BTemp)] = CTemp
    except:
        pass
    print(sum(A))
