(let* ((n (read))
    (a (make-array n))
    (q 0))
    (dotimes (i n)
        (setf (aref a i) (read))
    )
    (setq q (read))
    (dotimes (i q)
        (let ((b (read))
            (c (read))
            (ans 0))
            (dotimes (j n)
                (if (= (aref a j) b)
                    (progn
                    (setf (aref a j) c)
                    (incf ans c))
                    (incf ans (aref a j))
                )
            )
        (format t "~D~%" ans)
        )
    )
)