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

data = [0] * 100000

def my_sum(d):
    retval = 0

    for i in range(len(d)):
        if d[i] == 0:
            continue
        retval += d[i] * i
    return retval

for i in A:
    data[i] += 1
 
for i in range(Q):
    B, C = map(int, input().split())

    if data[B] != 0:
        data[C] += data[B]
        data[B] = 0
 
    print(my_sum(data))