def main():
    import collections
    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 = sum(A_list)
    for i in range(Q):
        B[i], C[i]  = map(int, input().split())

        num = A_list.count(B[i])
        #print(num)
        if B[i] > C[i] :
            ans = ans - (B[i] - C[i]) * num
        else :
            ans = ans + (C[i] - B[i]) * num
        for j in range(len(A_list)) :
            if B[i] in A_list :
                rep = A_list.index(B[i])
                A_list[rep] = C[i]
            else :
                #print("in")
                break
        print(ans)

if __name__ == '__main__':
    main()