Here we are given that the order of the group is 10 and a is the generator..
Hence a10 = e where e is the identity element but we dont know about a8..Hence we have to write it in terms of a10 as that is a known result.
Let we have y = a40 which can be written as : a40 = (a10)4 = e4 = e ...(1)
Also , a40 = (a8)5 = e [ Follows from (1) ]
Hence it means that a8 is repeated 5 times in order to get the identity element e which is least number of times to do so.
Also from the corollary of the Lagranges' Theorem ,
Order of an element divides the order of the order of the group (The actual theorem is order of a subgroup divides the order of the group)
Here 5 divides the order of group i,e, 10..
Hence order of a8 = 5