N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B,C = [],[]
for _ in range(Q):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)

a = {}
for i in range(N):
    if A[i] in a:
        a[A[i]] += 1
    else:
        a[A[i]] = 1

for i in range(Q):
    if C[i] not in a:
        a[C[i]] = 0

    if B[i] in a:
        a[C[i]] += a[B[i]]
        remove_value = a.pop(B[i])
    
    ans = 0
    for k in a:
        ans += k*a[k]
    print(ans)