#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define endl '\n'
#define inf int(1e9)
#define mod 1000000007
#define fastio std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i,a,b) for( int i=a; i<b; i++)
#define ii pair < ll , ll >
#define F first
#define S second
#define input freopen("C:\\Users\\ASUS\\Desktop\\input.txt","r+",stdin)
#define output freopen("C:\\Users\\ASUS\\Desktop\\output.txt","w+",stdout)
#define debug input; output
using namespace std;
const int N=1003;
string v[N];
ll t[N];
ll vis[N];
ll dp[N][N];
ll solve(int a, int b)
{
if (a>b)
return 0;
if( dp[a][b]==-1)
dp[a][b]= max(t[a] + min(solve(a+2,b),solve(a+1,b-1)) , t[b]+min(solve(a,b-2),solve(a+1,b-1)) );
return dp[a][b];
}
int main()
{ fastio;
int tc;
cin>>tc;
while(tc--){
memset(dp,-1,sizeof(dp));
int n;
cin>>n;
ll sum=0;
for(int i=1;i<=n;i++){
cin>>t[i];
sum+=t[i];
}
ll ans=solve(1,n);
cout<<(ans-(sum-ans))<<endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIHN6KGEpIGEuc2l6ZSgpCiNkZWZpbmUgZW5kbCAnXG4nCiNkZWZpbmUgaW5mIGludCgxZTkpCiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKI2RlZmluZSBmYXN0aW8gc3RkOjppb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCkKI2RlZmluZSByZXAoaSxhLGIpIGZvciggaW50IGk9YTsgaTxiOyBpKyspCiNkZWZpbmUgaWkgcGFpciA8IGxsICwgbGwgPgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGlucHV0IGZyZW9wZW4oIkM6XFxVc2Vyc1xcQVNVU1xcRGVza3R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