import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    num = [0] * 100005
    A = list(map(int,input().split()))
    S = sum(A)
    for a in A:
        num[a] += 1
    
    Q = int(input())
    for _ in range(Q):
        c,d = map(int,input().split())
        x = num[c]
        S -= x * c
        num[d] += x
        S += x * d
        print(S)
if __name__ == '__main__':
    main()