The angle between them (call it c) is 125°
At 12 knots, after 2 hours ship A will have travelled A = 24 nautical miles.
At 16 knots, sfter 2 hours ship B will have travelled B = 32 nautical miles.
Cosine rule: C2 = A2 + B2 - 2ABcos(c)
so distance between ships is C = sqrt(242 + 322 -2*24*32*cos(125°)) nautical miles.
I'll leave you to crunch the numbers.