Quantum Permanents and Hafnians via Pfaffians