After 12 minutes switch off P See , Work done by Q in 16 minutes -1/32×16=1/2 That means P has to do 1/2 of the work left Therefore Time taken by P,=24×1/2=12 minutes. So after 12minutes P can be closed
Let volume of cistern be V
Flow rate through pipe P is V/24
Flow rate through pipe Q is  V/32
Flow rate through both pipes = V/32+V/24= 7V/96
let first pipe be turn off after x minute
Cistern will be filled by 7V*x/96 volume
Rest of volume be filled by pipe Q for 16-x minutes
Volume filled by Q for 16-x minute is V*(16-x)/32
So we have 7Vx/96+ V(16-x)/32 = V
             ⇒ 7x/96 + (16-x)/32 = 1
             ⇒ 7x +48 - 3x = 96
             ⇒ 4x = 48
             ⇒   x = 12
First pipe should be closed after 12 minutes.