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

data = {}

def my_sum(d):
    retval = 0

    for i in d.keys():
        retval += d[i] * i
    return retval

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

    if B not in data.keys():
        print(my_sum(data))
        continue
 
    if C in data.keys():
        data[C] = data[C] + data[B]
    else:
        data[C] = data[B]
    del data[B]
 
    print(my_sum(data))