import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
q = int(input())
M=[list(map(int,input().split())) for _ in range(q)]
Sum = sum(A)
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1
for i in M:
    a,b=i[0],i[1]
    if a not in d:
        L = list(d.items())
        print(sum([x*y for x,y in L]))
        continue
    elif b in d:
        d[b]+=d[a]
    else:
        d[b]=d[a]
    d.pop(a)
    L = list(d.items())
    print(sum([x*y for x,y in L]))
