(let* ((n (read))
    (a (make-array 100001 :initial-element 0))
    (q 0)
    (ans 0))
    (dotimes (i n)
        (let ((d (read)))
        (incf (aref a i))
        (incf ans d)
        )
    )
    (setq q (read))
    (dotimes (i q)
        (let ((b (read))
            (c (read)))
            (incf (aref a c) (aref a b))
            (incf ans (* (aref a b) (- c b)))
            (setf (aref a b) 0)
        )
        (format t "~D~%" ans)
    )
)