Code problem not working

My answer is correct in code blocks ide and jupyter notebook but when i sent the code it is showing timelimit error.

from math import sqrt
n = int(input())
for i in range(1,n+1):
A = int(input())
print()
for a in range(0,A+1):
for b in range(0,A+1):
try:
b1 = sqrt(A-(aa))
a1 = sqrt(A-(b
b))
if (a<=b1 and b1==b) or (a1<=b and a1==a):
print("({},{})".format(a,b),end=" ")

        except:
            pass

Timelimit error doesn’t imply that your code is wrong , it simply implies that your program is taking more time than the allotted time to get executed .
Some changes that you can make to reduce the time complexity -

  1. Break out of loop when a*a >n
  2. Start the range of loop b from a and not 0, also break out of this loop when b*b >n
  3. In if condition you can check (a * a + b * b == n) and print the values of a and b

The idea is to put two nested loops and print those numbers whose squared sum is equal to the given number.