n = int(input())
A = map(int, input().split())
q = int(input())
move = []
l={}
for _ in range(q):
    b, c = map(int, input().split())
    move.append((b,c))
for i in A:
    if i in l:
        l[i]+=1
    else:
        l[i]=1
for (f,t) in move:
    if t in l:
        l[t]+=l[f]
    else:
        l[t]=l[f]
    l[f]=0
    sum = 0
    for k,v in l.items():
        sum += k*v
    print(sum)