Two pipes P and Q can fill a tank in 6 hours and 9 hours respectively, while a third pipe R can empty the tank in 12 hours. Initially, P and R are open for 4 hours. Then P is closed and Q is opened. After 6 more hours R is closed. The total time taken to fill the tank (in hours) is _____