def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for i in range(Q)]

    g = {}
    for a in A:
        if a not in g:
            g[a] = 1
        else:
            g[a] += 1

    for i in range(Q):
        B, C = tuple(BC[i])
        if B in g:
            t = g.pop(B)
            if C in g:
                g[C] += t
            else:
                g[C] = t
        ans = 0
        for k, v in g.items():
            ans += k * v
        print(ans)


if __name__ == "__main__":
    main()
