This solution only works for k = 3.