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

bc = [map(int, input().split()) for _ in range(Q)]
b, c = [list(i) for i in zip(*bc)]

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