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):
        if qu[i][0] not in a:
            continue
        for j in range(n):
            if a[j]==qu[i][0]:
                a[j]=qu[i][1]
        pr.append(str(sum(a)))
    print("\n".join(pr))
if __name__ == "__main__":
    main()