optimize this!!!

import math
def main():
t=input()
for i in range(int(t)):
n,k=input().split()
pwr(int(n),int(k))
def pwr(n,k):
s=1+int(nmath.log(n,10))
if(k!=s):
a=int(10**((n
math.log(n,10)-(s-k))))
else:
a=nn
j=1
d=n
while(d>0):
if(d&1):
j=j*n%(10
k)
n=(n*n)%(10**k)
d>>=1
print(a,j)
if name==‘main’:main()

Please mention problem code.

@argonaut i think it is rise and fall of power!!!

Yeah it is the rise and fall of power (practice problem ( easy)) … It works fine on idle for any number till 10^9… But is not able to over come that time limit exceeded error… Plz modify this to an acceptable code… I have tried it a super lot of times…

//