import numpy as np

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    A = np.array(A)

    SUM = []
    for i in range(Q):
        B, C = list(map(int, input().split()))
        if i == 0:
            A = np.where(A == B, C, A)
            SUM.append(sum(A))
        else:
            count = np.count_nonzero(A == B)
            SUM.append(SUM[i-1]+(C-B)*count)
            if count == 0:
                continue
            A = np.where(A == B, C, A)

    for s in SUM:
        print(s)
