N = int(input())
An = list(map(int, input().split()))
Q = int(input())


for i in range(Q):
    b, c = map(int, input().split())
    for j, name in enumerate(An):
        if An[j] == b:
            An[j] = c
    
    print(sum(An))