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