n = int(input())
als = list(map(int,input().split()))
q = int(input())
for i in range(q):
    b, c = map(int,input().split())
    if b in als:
        for j in range(n):
            if als[j] == b:
                als[j] = c
    print(sum(als))