def main():
    N = int(input())
    A = [int(a) for a in input().split(" ")]
    Q = int(input())

    sum_list = list()
    for i in range(Q):
        B, C = input().split(" ")
        # sum = 0
        for idx, value in enumerate(A):
            if value ==int(B):
                # sum += int(C)
                A[idx] = int(C)
            else: 
                # sum += value
                pass
            if not int(B) in A:
                break

        sum_list.append(sum(A))
    for value in sum_list:
        print(value)
if __name__=="__main__":
    main()