Wrong answer in "Chef and Way" (CHRL4)

I have been stuck at this problem, I cann’t seem to figure out what I did wrong. I checked the logarithmic solution provided in the editorial but I was trying something else, Can someone point out what am I doing wrong in my code. That would be a great help.
My code: https://www.codechef.com/viewsolution/31627815
Problem : https://www.codechef.com/problems/CHRL4

Suppose there was
a = 1000000006
and b =2
if multiplied by 1000000006
then before having modulo
we know a>b, a=1000000006 x 1000000006, b=2 x 1000000006
and after modulo we get a=1 and b=1000000005
so here a<b

Since we are asked to find the value and whatever answer we get must be minimal will be modulo with 1000000007
It is not asked the minimal value after the modulo.
Hope so you get the difference and mistake in your solution