def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    B = [0 for i in range(Q)]
    C = [0 for i in range(Q)]
    
    A_kind = []
    A_num = []
    ans = 0
    for a in A:
        ans += a
        if not a in A_kind:
            A_kind.append(a)
            A_num.append(1)
        else:
            A_num[A_kind.index(a)] += 1
    
    for q in range(Q):
        B[q],C[q] = map(int,input().split())
        
    for q in range(Q):
        b = B[q]
        c = C[q]
        if b in A_kind:
            n = A_kind.index(b)
            ans += (c - A_kind[n])*A_num[n]
            if c in A_kind:
                A_num[A_kind.index(c)] += A_num[n]
                del A_kind[n]
                del A_num[n]
            else:
                A_kind[n] = c
        print(ans)
    
if __name__ == '__main__':
    main()