n = int(input())
l = list(map(int, input().split()))
for _ in range(int(input())):
    x, y = map(int, input().split())
    for i in range(n):
        if l[i] == x:
            l[i] = y
    print(sum(l))