
#=input()
n=int(input())
#=map(int,input().split())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for _ in range(q)]

sum = 0
for m in range(n):
    sum += a[m]
for i in range(q):
    w = bc[i][0]
    e = bc[i][1]
    cnt = a.count(w)
    a = [e if j==w else j for j in a]
    sum += (e-w)*cnt
    print(sum)