Let me know if you still need help.
In generally, you can pass an array of layers to a function.
Each time you loop through the array, you execute an querytask.
Last, use an instance of "dojo/promise/all" to wait until all results are received and do something.