This is a beautiful problem to test whether a student actually understands
Newton's 2nd law of motion . . . Force = (mass) x (acceleration). 
That simple law is all you need to solve this problem, but you need to 
use it a few times.
m₁ alone:
 Force = (mass) x (acceleration)
 36 N = ( m₁ ) x (6 m/s²)
 m₁ = (36 N) / (6 m/s²) 
  m₁ = 6 kilograms .
m₁ and m₂ glued together:
 Force = (mass) x (acceleration)
 36 N = (6 kg + m₂) x (2 m/s²)
 6 kg + m₂ = (36 N) / (2 m/s²) = 18 kilograms
 m₂ = 12 kilograms .
m₂ alone:
 Force = (mass) x (acceleration)
 36 N = (12 kg) x (acceleration)
 Acceleration = (36 N) / (12 kg) 
  Acceleration = 3 m/s²