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


def aaa(n):
    if n == B:
        return C
    else:
        return n


for i in range(Q):
    B, C = map(int, input().split())
    A = list(map(aaa, A))
    print(sum(A))



