MATPAN:please tell me the run time error in it

PROBLEM PRACTISE BEGINNERS MATPAN

    #include<stdio.h>

       int main()
           {
int t;
scanf("%d",&t);
while(t--)
{
	int p[1000],i,sum;
	char str[50000];
	for( i=97;i<=122;i++)
	scanf("%d",&p[i]);
	scanf("%s",str);
	
	for(i=97;i<=122;i++)
	{ 
		int flag=0;
		for(int j=0;str[j]!='\0';j++)
		{
			int ascii=(int)str[j];
			if(ascii==i)flag=1; 
			
		}
	if(flag==0)sum+=p[i];
	}
	printf("%d\n",sum);
}

return 0;
}

try adding this line in the beginning of each test case:

sum = 0;

sum=0 is missing from your code.
This will cause a random value to be stored in sum in the beginning.

//