Q-switched cavity