def main():
    n=int(input())
    a=list(map(int,input().split()))
    q=int(input())
    qu=[]
    pr=[]
    for i in range(q):
        qu.append(list(map(int,input().split(' '))))
    for i in range(q):
        for j in range(n):
            if a[j]==qu[i][0]:
                a[j]=qu[i][1]
        pr.append(sum(a))
    for i in pr:
        print(i)
if __name__ == "__main__":
    main()