N = int(input())
A = list(map(int, input().split()))
ans = sum(A)
Q = int(input())

for q in range(Q):
    b, c = map(int, input().split())
    for i in range(N):
        if A[i] == b:
            A[i] = c
            if b <= c:
                ans += c - b
            else:
                ans -= b - c
    print(ans)