Do you know what a derangement of a queue of n objects is?
Derangements are permutations in which each member is active.
2143 is a derangement of 1234 whereas 2431 is not because the 3 is inactive.
If D(n) is the number of derangements on a queue of n objects;
Given any queue of the n balls from the first group, there are D(n) queues of the other group of balls that do not have any matching positions with the given queue.
Thus the answer to your question is .