n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

appeared = list(set(list_a))
counts = []

for i in range(len(appeared)):
    counts.append(list_a.count(appeared[i]))

q = int(input())
ans = 0

for i in range(len(appeared)):
    ans += appeared[i] * counts[i]

for i in range(q):
    b, c = map(int, input().split())

    if b in appeared:
        b_idx = appeared.index(b)
        b_count = counts[b_idx]
        ans += b_count * (c - b)
        print(ans)

        if c in appeared:
            c_idx = appeared.index(c)
            counts[c_idx] += counts[b_idx]
            appeared.pop(b_idx)
            counts.pop(b_idx)
        else:
            appeared.append(c)
            counts.append(counts[b_idx])
            appeared.pop(b_idx)
            counts.pop(b_idx)
    else:
        print(ans)
