def main():
    N = int(input())
    A = input()
    Q = int(input())

    answer = sum(list(map(int, A.split())))
    A = A.replace(" ", "")

    for i in range(Q):
        B, C = input().split()
        numB = A.count(B)

        answer = answer + (int(C) - int(B)) * numB
        print(answer)

        A = A.replace(B, C)

if __name__ == "__main__":
    main()