#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int M=1e5+10;
int t,n;
long long a[M];
long long sum;
int minx;
long long maxx;
int mi;
long long ans;
long long dp[M];
int main(){
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
cin>>t;
while(t--){
memset(dp,0,sizeof(dp));
memset(a,0,sizeof(a));
sum=0;
maxx=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
dp[i]=a[i];
}
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++){
if(a[i]>a[j]){
dp[i]=max(dp[i],dp[j]+a[i]);
}
maxx=max(maxx,dp[i]);
}
}
ans=sum-maxx;
cout<<ans<<endl;
}
return 0;
}