Please help me with this problem (i am continuously getting wa)

for this problem CodeChef: Practical coding for everyone i am getting an wrong answer but my test cases and run are showing successfully executed please help me find out the error.
here is code :-1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
ll t;
cin>>t;
while(t–)
{
ll n,q,i;
cin>>n>>q;
ll f[100000],d[100000];
for(i=0;i<q;i++)
{
cin>>f[i]>>d[i];

	}
	
    ll g,s=0;
	for(i=1;i<q;i++)
	{
		
		g=d[i]-f[i];	
		if(g<0)
		{
			g=g*-1;
    	}
    	
    	s=s+g;
		
	}
	  
	  ll h;
	  for(i=0;i<q-1;i++)
	  {
	  	
	  	h=d[i]-f[i+1];
	  	if(h<0)
	  	{
	  		h=h*-1;
			  	
	  	}
	  	
	  	s=s+h;
	  	
	  }
	  
	  
	cout<<s+d[0]<<endl;

}

return 0;

}
please mark out the error
thank in advance