```
lim=int(1000000007)
t = int(input())
for i in range(t):
n,c =input().split()
n=int(n)
c=int(c)
if n%2==1:
g1 =c**(5*n*n)%lim
g2=(c**(n*n+(n*n+1)/2)) %lim
g2 =2*g2
g3 =c**(2*n*n+(n*n+1)/2) %lim
print (int(((g1+g2+g3)/4))%lim)
else :
g1 =c**(5*n*n)%lim
g2=(c**(n*n+(n*n)/4)) %lim
g2 =2*g2%lim
g3 =c**(2*n*n+(n*n)/2) %lim
print (int(((g1+g2+g3)/4))%lim)
```

` `

Link to the problem https://www.codechef.com/problems/ICPC16E

I have solved this problem but I am not able to pass the timelimit

Can someone tell the improvement in the code …