#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long int

int T,n; ll ans;
int arr[200002]; ll S;
ll A[200002],B[200002];
ll C[200002],D[200002];
ll AC[200002],BD[200002];
ll I1[200002],I2[200002];
int tree[200002];
inline bool comp1(int a,int b)
{
	if((a&1)==(b&1)) return AC[a]<AC[b];
	return (a&1)>(b&1);
}
inline bool comp2(int a,int b)
{
	if((a&1)==(b&1)) return BD[a]<BD[b];
	return (a&1)>(b&1);
}
inline int lb(int x){return x&(-x);}
void update(int i)
{
	for(int j=i+1;j<=n+1;j+=lb(j))
		tree[j]++;
	return;
}
int query(int i)
{
	int res=0;
	for(int j=i+1;j>0;j-=lb(j))
		res+=tree[j];
	return res;
}

void solve(int l,int r)
{
	A[l-1]=0; D[l-1]=0;
	for(int i=l;i<=r;i++){
		A[i]=A[i-1]+arr[i];
		D[l-1]+=arr[i];
	}
	for(int i=l;i<=r;i++)
		D[i]=D[i-1]-arr[i];
	B[l-1]=0; B[l]=-arr[l];
	for(int i=l+1;i<=r;i+=2){
		B[i]=B[i-2]+arr[i-1]-arr[i];
		B[i+1]=B[i-1]+arr[i]-arr[i+1];
	}
	for(int i=l-1;i<=r;i++)
		C[i]=B[i];
	for(int i=l-1;i<=r;i++){
		AC[i]=A[i]+C[i];
		BD[i]=B[i]+D[i];
		I1[i]=I2[i]=i;
	}
	sort(I1+l-1,I1+r+1,comp1);
	sort(I2+l-1,I2+r+1,comp2);
	int m=l-1+(r-l+2+(r&1))/2,p1=l-1;
	for(int i=0;i<=n;i++)
		tree[i+1]=0;
	for(int i=l-1;i<m;i++){
		while(p1<m&&AC[I1[p1]]<BD[I2[i]]){
			if(l==1||I1[p1]>=3) update(I1[p1]); p1++;
		}
		if(I2[i]<r) ans+=query(I2[i]);
	}
	for(int i=0;i<=n;i++)
		tree[i+1]=0;
	int p2=m;
	for(int i=m;i<=r;i++){
		while(p2<=r&&AC[I1[p2]]<BD[I2[i]]){
			if(l==1||I1[p2]>=3) update(I1[p2]); p2++;
		}
		if(I2[i]<r) ans+=query(I2[i]);
	}
	return;
}

int main(void)
{
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		ans=S=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&arr[i]);
			S+=arr[i];
		}
		if(n==1){printf("1\n");continue;}
		if(n==2){printf("%d\n",arr[1]==arr[2]?1:2);continue;}
		for(int i=1;i<=n-2;i++){
			S-=2*arr[i];
			if(S<0) ans++;
		}
		solve(1,n);
		arr[n-1]-=arr[n];
		solve(1,n-1);
		arr[2]-=arr[1];
		solve(2,n-1);
		arr[n-1]+=arr[n];
		solve(2,n);
		printf("%lld\n",ans%998244353);
	}
	return 0;
}
/*
1
15
1 2 3 2 3 3 2 1 1 2 2 1 2 3 3
*/