A ship travels at a bearing of 045 degrees for 12km. It then changes direction and travels x km at a bearing of 150 degrees. The ship then returns to its starting point by sailing due west (a bearing of 270 degrees). Find the exact value of x.