N=int(input())

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

Amap=dict()

for i in range(N):
    if A[i] in Amap:
        Amap[A[i]]+=1
    else:
        Amap[A[i]]=1

# print(Amap)

Q=int(input())
ans = list()
for i in range(Q):
    B, C =list(map(int,input().split()))

    if B in Amap:
        if C in Amap:
            Amap[C] += Amap[B]
        else:
            Amap[C] = Amap[B]

    else:
        if C in Amap:
            Amap[C] += 0
        else:
            Amap[C] = 0

    Amap[B] = 0
    # print(i, B, C, Amap)


    s = 0
    for k in Amap.keys():
        s += (int(k)*Amap[k])
    ans.append(s)
    # print(s)

for s in ans:
    print(s)