def main():
    N = int(input())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))
    Q = int(input())
    B = [0] * Q
    C = [0] * Q
    ans_list = []
    for i in range(Q):
        B[i], C[i]  = map(int, input().split())
        val_list = my_index_multi(A_list, B[i])
        for j in val_list :
            A_list[j] = C[i]
        ans_list.append(sum(A_list))
    for ans in ans_list :
        print(ans)

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

if __name__ == '__main__':
    main()