Getting TLE in generate prime problem

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(" ")

hi ravi
try using different approaches and logics to get the optimal solutions.
if you are not able to decode the logic try refering hints in editorial

try to loop till sqrt of number in order to check the prime
it will highly optimised it