# coding: utf-8
# Your code here!
from operator import mul
import collections
N=input()
AList = list(map(int, input().split()))
Q=int(input())
BCList=[list(map(int, input().split())) for i in range(Q)]

CountList = collections.Counter(AList)
CountList=dict(CountList)
#print(CountList)

def KAKEZAN(CountList):
    KARI=(map(mul,(CountList.keys()),(CountList.values())))
    print(sum(list(KARI)))

A=0
for i in range(Q):
    #print(CountList)
    try:
        SUCHI=CountList[BCList[i][0]]
        A=1
    except KeyError:
        pass
    try:
        del CountList[BCList[i][0]]
        A+=1
    except KeyError:
        pass
    if A==2:
        try:
            CountList[BCList[i][1]]+=SUCHI
        except KeyError:
            pass
    A=0
    KAKEZAN(CountList)
