Solution of the test task from Engine6 (http://engine6.com)