#atcoder template

def main():

    import sys

    imput = sys.stdin.readline

    #文字列入力の時は上記はerrorとなる。

    #ここにコード

    #input

    from collections import Counter

    N = int(eval(input()))

    A = list(map(int, input().split()))

    D = Counter(A)

    S = sum(A)

    Q = int(eval(input()))

    B = [0] * Q

    C = [0] * Q

    for i in range(Q):

        b, c = list(map(int, input().split()))

        x = D[b]

        y = D[c]

        temp = -x * b + x * c

        print((S+temp))

        S += temp

        D[b] = 0

        D[c] += x  



    #N = 1のときなどcorner caseを確認！

if __name__ == "__main__":

    main()
#atcoder template

def main():

    import sys

    imput = sys.stdin.readline

    #文字列入力の時は上記はerrorとなる。

    #ここにコード

    #input

    N = int(eval(input()))

    A = list(map(int, input().split()))

    Q = int(eval(input()))

    B = [0] * Q

    C = [0] * Q

    for i in range(Q):

        B[i], C[i] = list(map(int, input().split()))

        

    #output

    from collections import Counter

    D = Counter(A)

    S = sum(A)



    for i in range(Q):

        x = D[B[i]]

        temp = S - x*B[i] + x*C[i] 

        print(temp)

        D[B[i]] = 0

        D[C[i]] += x

        S = temp    



    #N = 1のときなどcorner caseを確認！

if __name__ == "__main__":

    main()

# atcoder template
def main():
    import sys

    imput = sys.stdin.readline
    # 文字列入力の時は上記はerrorとなる。
    # ここにコード
    # input
    from collections import Counter

    N = int(eval(input()))
    A = list(map(int, input().split()))
    D = Counter(A)
    S = sum(A)
    Q = int(eval(input()))
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        b, c = list(map(int, input().split()))
        x = D[b]
        y = D[c]
        temp = -x * b + x * c
        print((S + temp))
        S += temp
        D[b] = 0
        D[c] += x
    # N = 1のときなどcorner caseを確認！


if __name__ == "__main__":
    main()

# atcoder template
def main():
    import sys

    imput = sys.stdin.readline
    # 文字列入力の時は上記はerrorとなる。
    # ここにコード
    # input
    N = int(eval(input()))
    A = list(map(int, input().split()))
    Q = int(eval(input()))
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        B[i], C[i] = list(map(int, input().split()))
    # output
    from collections import Counter

    D = Counter(A)
    S = sum(A)
    for i in range(Q):
        x = D[B[i]]
        temp = S - x * B[i] + x * C[i]
        print(temp)
        D[B[i]] = 0
        D[C[i]] += x
        S = temp
    # N = 1のときなどcorner caseを確認！


if __name__ == "__main__":
    main()

-    from collections import Counter - -    D = Counter(A) -    S = sum(A) -        b, c = list(map(int, input().split())) -        x = D[b] -        y = D[c] -        temp = -x * b + x * c -        print((S + temp)) -        S += temp -        D[b] = 0 -        D[c] += x +        B[i], C[i] = list(map(int, input().split())) +    # output +    from collections import Counter + +    D = Counter(A) +    S = sum(A) +    for i in range(Q): +        x = D[B[i]] +        temp = S - x * B[i] + x * C[i] +        print(temp) +        D[B[i]] = 0 +        D[C[i]] += x +        S = temp