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
    for i in range(Q):
        B[i], C[i]  = map(int, input().split())
    #print(A_list)
    ans_list = []
    for i in range(Q) :
        val_list = my_index_multi(A_list,B[i])
        #print(val_list)
        for j in val_list :
            #print(A_list[j])
            #print(B[i])
            #print(C[i])
            A_list[j] = C[i]
            #A_list[j].replace(str(B[i]), str(C[i]))
        #print(A_list)
        print(sum(A_list))
    #print(val_list)
    #A_list.replace(B[0],C[0])

    #A_list = list(map(int, A_list))
    #print(sum(A_list))
    #print(B)
    #print(C)

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

if __name__ == '__main__':
    main()