The region subsequently became part of the Great Moravian state. Upon the invasion of the Hungarian tribes into the heart of the Great Moravian Empire around 899, the Lendians of the area declared their allegiance to Hungarian Empire. The region then became a site of contention between Poland, Kievan Rus and Hungary starting in at least the 9th century. This area was mentioned for the first time in 981 (by Nestor), when Volodymyr the Great of Kievan Rus took the area over on the way into Poland. In 1018 it returned to Poland, 1031 back to Rus, in 1340 Casimir III of Poland recovered it.