.
The way to solve this problem is to calculate the number of all possible configurations without the imposed constraint,
and then to subtract the number of configurations that fall under this constraint.
1. Calculating the number of all possible configurations without the imposed constraint.
You can create the first pair by = = 15 ways and place this pair to any of the 3 offices;
so you have 15*3 = 45 ways to do it.
You can create the second pair from remaining 4 people by = = 6 ways and to place it to any of remaining 2 offices.
You have 6*2 = 12 ways to do it.
With the third pair, you have nothing to select - NEITHER the pair NOR the office.
So, working without the constraint, you have 45*12 = 540 ways to do it.
2. Calculating the number of configurations that fall under this constraint.
You just have this "prohibited" pair of the two persons who hate each other.
So you need calculate how many pairs you can create with remaining 4 people and distribute them.
You can create the first pair in = = 6 ways and place it to any of 3 offices: 6*3 = 18 options.
Regarding the second pair, you just have no choice (you have only one selection) and can place this pair to any of 2 remaining offices.
In all, you have 18*2 = 36 "prohibited" options under the restriction.
So, the final answer is: 540 - 36 = 504 ways.