Help me in solving MAKEDIV3 problem

My issue

What to do if get run time error

My code

# cook your dish here
# cook your dish here
import math
t=int(input())
while(t!=0):
    n=int(input())
    temp=10**(n-1)
    temp1=10**n
    for i in range(temp,temp1):
        if(i%3==0 and i%9!=0 and i%2!=0):
            print(i)
            break
    t-=1

Learning course: Jump from 2* to 3*
Problem Link: Make it Divisible Practice Problem in Jump from 2* to 3* - CodeChef

@koushal10
loop through such a big number will give to tle .
There is another very interesting logic to it.
we n=know that a number divisible by 9 will always be divisible by 3 .
so the logic is print n-1 times 9 and one time 3.
refer my c++ code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    for(int i=0;i<n-1;i++)
	    cout<<9;
	    cout<<3;
	    cout<<endl;
	}
	return 0;
}