def main():
    n = int(input())
    a = list(map(int, input().split()))

    q = int(input())
    bc = [list(map(int,input().split())) for i in range(q)]
    
    for j in range(q):
        if (bc[j][0] not in a):
            print(sum(a))
            continue
        else:
            rep = [bc[j][1] if i == bc[j][0] else i for i in a]
            a = rep
            print(sum(a))

main()
