Solved problem P66 (more tests will be written to confirm this).