import numpy as np
def main():
    N = int(input())
    A = np.array([int(a) for a in input().split(" ")])
    Q = int(input())

    sum_list = list()
    for i in range(Q):
        B, C = input().split(" ")
        # sum = 0
        # breakpoint()
        A[A==int(B)] = int(C)
        sum_list.append(sum(A))

    for value in sum_list:
        print(value)
if __name__=="__main__":
    main()