def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    count = [0 for _ in range(10**5)]
    for i in range(n):
        count[a[i] - 1] += a[i]

    q = int(input())
    for _ in range(q):
        b, c = list(map(int, input().split()))
        count[c - 1] += count[b - 1] * (c / b)
        count[b - 1] = 0
        print(int(sum(count)))


if 'unittest' not in globals():
    resolve()