N=int(input())
lst=list(map(int,input().split()))
def swap(a,b):
    global lst
    lst=[b if i==a else i for i in lst]
for i in range(int(input())):
    a,b=map(int,input().split())
    swap(a,b)
    print(sum(lst))