Consider some complicated expression like the following: $$ Q[a,b]Q[a,c]M[a,c]M[a,b]$$ Where the lower case letters are matrix indices. I am looking for a way to make mathematica recognize all the existing indices automatically and just turn this expression into the sum: $$ \sum_a \sum_b \sum_c Q[a,b]Q[a,c]M[a,c]M[a,b]$$ Notice that this is not Einstein summation convention because I don't care how many times the indices are repeated.
Any ideas or references would be highly appreciated.