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 = []
    for i in A:
        if i == BTemp:
            i = CTemp
        ATemp.append(i)
    A = ATemp
    print(sum(A))
