String Similarity Code changes
<p>I programmed 1 code but it just passed 1 test case so i am not understanding what all mistake i did and what all changes do i got to make in the code so the question and the code is as follows:</p>

<p><strong>Question:</strong></p>

<p>For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3.</p>

<p>Calculate the sum of similarities of a string S with each of it's suffixes.</p>

<p>Input:
The first line contains the number of test cases T. Each of the next T lines contains a string each.</p>

<p>Output:
Output T lines containing the answer for the corresponding test case.</p>

<p>Constraints:
1 &lt;= T &lt;= 10
The length of each string is at most 100000 and contains only lower case characters.</p>

<p>Sample Input:
2
ababaa
aa</p>

<p>Sample Output:
11
3</p>

<p>Explanation:
For the first case, the suffixes of the string are "ababaa", "babaa", "abaa", "baa", "aa" and "a". The similarities of each of these strings with the string "ababaa" are 6,0,3,0,1,1 respectively. Thus the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.</p>

<p>For the second case, the answer is 2 + 1 = 3.</p>

<p>Code:</p>

<p><strong>String Similarity</strong></p>

<pre><code>import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Solution 
{
    int T,i;
    String[] S;
    String p;


    String inp;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    int count=0;

    public void StringSimilarity()
    {

        try
        {
            T=Integer.parseInt(br.readLine());  
            if(T&lt;1 &amp;&amp; T&gt;10)
                System.exit(0);
            S=new String[T];

        }
        catch(Exception e)
        {
        }

            for(i=0;i&lt;T;i++)
            {
                count=0;
             try
             {

                S[i]=br.readLine();
                S[i].toLowerCase();

             }
             catch(Exception e)
            {
                System.err.println("Error:" + e.getMessage());
            }

        }


        for(i=0;i&lt;T;i++)
        {
            int g=0;
            p=S[i];
            int a=0;
            a=p.length();
            count=0;
            char t[]=new char[a];


            for(int n=0;n&lt;p.length();n++)
            {
                t[n]=p.charAt(n);

            }




            int m=p.length();

            for(int f=0;f&lt;t.length;f++)
            {
                for(int j=0;j&lt;m-g;j++)
                {
                   if(p.charAt(0)== t[0])
                   {
                    if(p.charAt(j)== t[j])
                    {
                        count=count+1;

                    }
                   }
                }
                g=g+1;


                for(int k=0;k&lt;t.length-1;k++)
                {
                    t[k]=t[k+1];
                }
            }
            System.out.println(count);
        }
    }

    public static void main(String[] args)
    {
        Solution s=new Solution();
        s.StringSimilarity();

    }
}
</code></pre>
