problem code::SCHAR...WA but getting correct at my side

i have tested the programme many times on my compiler it is giving AC but on codechef it is showing WA …
please help if there are any errors or improvements

    #include<stdio.h>
    #include<string.h>
       #include<math.h>

int main()
{

int t; char str[100000+1]; long len;
unsigned long sum=0;

scanf("%d",&t);
while(t--)
{
	scanf("%s",str);
	len=strlen(str);
	
	for(long i=0;i<len;i++)
	{ int diff=(int)str[i]-(int)str[i+1];
	
	 sum+=abs(diff);
	if(str[len-1]==str[i+1])
	{
		 break;
		}	
	}
	
	
printf("%ul\n",sum);	
}
return 0;

}

your logic is not correct