Input (grade 7): In the last years of the Hafsids, Spain seized many of the coastal cities, but these were recovered by the Ottoman Empire.
Output (grade 12): In the last years of their reign, the Hafsids became weak and Spain took control of many city coasts until they were finally occupied by the Ottoman Empire.