Help me in solving MAKEDIV3 problem

My issue

cook your dish here

def findsum(x):
sum = 0
while x > 0:
sum = sum + x % 10
x = x // 10

return sum

n = int(input())

for i in range(n):
x = int(input())

for j in range(10 ** (x - 1), 10 ** x):
    if j % 3 == 0 and findsum(j) % 9 != 0:
        print(j)
        break

why this code is getting runtime error

My code

# cook your dish here
def findsum(x):
    sum = 0
    while x > 0:
        sum = sum + x % 10
        x = x // 10

    return sum

n = int(input())

for i in range(n):
    x = int(input())

    for j in range(10 ** (x - 1), 10 ** x):
        if j % 3 == 0 and findsum(j) % 9 != 0:
            print(j)
            break

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

@tanuj_gupta
the simpler logic is print n-1 times 9 and one time 3