in the below code of generating prime nos i am getting time limit exceeded error.can u tell what is the other way to do it in python
t=int(input())
for i in range(t):
m,n=input().split()
m=int(m)
n=int(n)
for j in range(m,n+1):
for k in range(2,j):
if k==j:
print(j,end=’ ')
elif j%k==0 :
break
print(" ")