Consider $(q\_1,q\_2,...) \in Q$ non-intersecting sets of distinct elements $(e\_{(i,1)},e\_{(i,2)},...)\in q\_i$.


How many ways can one write down an ordering of all of the $\sum\_j |q\_j|$ elements s.t.:


(1) For any two elements $e\_{(a,1)}$ & $e\_{(b,1)}$, where $a < b$, it must be the case that $e\_{(a,1)}$ comes before $e\_{(b,1)}$ in the ordering;


(2) For any two elements $e\_{(i,a)}$ & $e\_{(i,b)}$, where $a < b$, and for any set $q\_i$, it must be the case that $e\_{(i,a)}$ comes before $e\_{(i,b)}$ in the ordering;


Is there a closed-form expression for this count?


For example, if there are only two sets $q\_1$ and $q\_2$, each with three elements, one possible ordering could be: $(e\_{(1,1)},e\_{(1,2)},e\_{(2,1)},e\_{(2,2)},e\_{(1,3)},e\_{(2,3)})$.



The number of orderings of elements with order-of-appearance constraints
Notice that your ordering defines a partial order on $Q$ which has a tree as its Hasse diagram. The number you are trying to calculate is the number of [linear extensions](http://en.wikipedia.org/wiki/Linear_extension) of this poset, or in other words the number of increasing labelings of your tree.


When the Hasse diagram is a forest, this calculation is given by Knuth's hook length formula. There is even a q-analogue by Bjorner and Wachs. For your example the formula gives
$$\frac{1}{\prod\_{k\geq 1}(\sum\_{i\geq k} |q\_i|)}\frac{\left(\sum\_i |q\_i|\right)!}{\prod\_i (|q\_i|-1)!}.$$


