#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B = []
    C = []
    for i in range(Q):
        b, c = map(int, input().split())
        B.append(b)
        C.append(c)

    #output
    from collections import Counter
    D = Counter(A)
    S = sum(A)

    for i in range(Q):
        x = D[B[i]]
        print(S - x*B[i] + x*C[i])
        D[C[i]] += x
        S = S -x*B[i] + x*C[i]

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()