def main():
    N, *X = map(int, open(0).read().split())
    A = X[:N]
    Q = X[N]
    s = sum(A)
    B = {}
    for a in A:
        if a not in B:
            B[a] = 0
        B[a] += 1

    ans = []
    for i in range(Q):
        b, c = X[N + 1 + 2*i], X[N + 1 + 2*i + 1]
        if b in B:
            num = B[b]
            s += (c - b)*num
            if c not in B:
                B[c] = 0
            B[c] += num
        ans.append(str(s))
    print('\n'.join(ans))

if __name__ == '__main__':
    main()
