Some test cases not working

Please correct my logic. Thanks

it is mentioned in the question that the k can be greater then the n so you have to handle that case as well.
you can handle that by doing taking modulus.