N = int(input())
numbers = list(map(int,input().split()))
numOfOperation = int(input())
for i in range(numOfOperation):
    B,C = map(int,input().split())
    for j in range(len(numbers)):
        if numbers[j] == B : numbers[j] = C
    print(sum(numbers))
