n=int(input())
list=[int(x) for x in input().split()]
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    for i in range(len(list)):
        if list[i]==b:
            list[i]=c
    print(sum(list))