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
sumflag=False
for (f,t) in move:
    if f in l:
        if t in l:
            l[t]+=l[f]
            l[f]=0
        else:
            l[t]=l[f]
            l[f]=0
        sum = 0
        for k,v in l.items():
            sum += k*v
        print(sum)
        sumflag=True
    else:
        if sumflag:
            print(sum)
        else:
            for k,v in l.items():
                sum += k*v
                print(sum)
                sumflag=True