Python Bigger is Greater optimization : python gurus.
I am trying to finish the below challenge and don't want to use permutation.
https://www.hackerrank.com/challenges/bigger-is-greater
The below code works well for small piece of test data, however it cannot pass  100000 cases. Could any masters help to provide some suggestions to optimize the below code. Much appreciated.

t=int(raw_input())
for _ in range(t):
    s=list(raw_input().strip())#change to list
    pos = -1#check pos, if pos is smaller, it's bigger lexilogical, so only choose small pos
    i_temp=0

    for i in reversed(range(len(s))):
        for j in reversed(range(i)):
            if s[i]>s[j]: #last letter is bigger than previous, in this case , we can swap to previous one, and found bigger one.
                if j>pos:
                    pos=j#new place
                    i_temp=i
                if j<pos:
                    break #already found good one
            if i<pos:
                break #already found good one
    if  pos>=0:                                              
        s_tmp=s[pos]                                          
        s[pos]=s[i_temp]                                      
        s[i_temp]=s_tmp                                          
        s1 = s[pos+1:]                  #get string for smallest   
        s1.sort()                                                
        print ("".join(s[:pos+1]+s1))            
    else:                                                        
        print ("no answer")                                              
