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