'Team Split' problem
Rewafadhabihlgdity

(If you can't tell, that is supposed to say 'readability'). Leaves some things to be desired.


Variable names: All your variable names are three characters or less. This makes it very hard to read your code. Renaming r to playerCount is a start, and S can be called strengths. so1 and so2 should also be renamed, along with t, p and q. Make variables self-documenting by giving them a reasonable name.
Spacing: Dontyoufinditabithardtoreadtext/codethatdoesntcontainanyspacesandappropriatepunctuation? (I'm exagerating just to prove a point). Even though it is a bit easier to read lack of code spacing than lack of word-spacing in written text, I find a line like this hard to read:

S[k]=((a*S[k-1]*S[k-1])+(b*S[k-1])+c)%1000000;


For this particular line, consider rewriting it to this:

int previous = strengths[index - 1];
strengths[index] = (a * previous * previous + b * previous + c) % 1000000;


By using better variable names, adding space, extracting a variable, and removing unnecessary parenthesis that line becomes a lot more readable.

The lack of good variable names and spacing especially made this part of the code really hard for me to understand what you are doing and why:

for(int p=r-1,q=r-2;p&gt;=0;p=p-2,q=q-2){
     if(q&gt;=-1){
         so1=so1+S[p];
         if(q&gt;=0){
             so2=so2+S[q];
         }
     }
}



Speed

Unable to reproduce / Unclear what the issues are. It seems to me that your code is quite fast. Even the input 10000000 5 6 7 8 calculated with reasonable speed IMO.

Extensibility

For testing purposes, to ensure both correct results and fast enough results, it would be useful to extract a method to do the actual calculations, and then your outermost loop could be:

        for (int i = 0; i &lt; count; i++) {
            String s[] = sc.readLine().trim().split(" ");
            int playerCount = Integer.parseInt(s[0]);
            a = Integer.parseInt(s[1]);
            b = Integer.parseInt(s[2]);
            c = Integer.parseInt(s[3]);
            d = Integer.parseInt(s[4]);
            System.out.println(determineTeamDifferences(playerCount, a, b, c, d));
        }