How to optimize this python script further?
===

I've created this script to compute the [string similarity][1] in python. Is there any way I can make it run any faster?

    tries = input()
    while tries > 0:
    	mainstr = raw_input()
    	tot = 0
    	ml = len(mainstr)
    	for i in xrange(ml):
    		j = 0
    		substr = mainstr[i:]
    		ll = len(substr)
    		for j in xrange(ll):
    			if substr[j] != mainstr[j]:
    				break
    			j = j + 1
    		tot = tot + j
    	print tot
    	tries = tries - 1

  [1]: https://www.interviewstreet.com/challenges/dashboard/#problem/4edb8abd7cacd
