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