#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        ll v[n+2]={0},pre[n+2]={0};
        v[n]=0;
        cin>>pre[0];
        loop(i,1,n)
        {
            cin>>v[i];
            pre[i]=v[i]+pre[i-1];
        }
        ll ans=pre[k];
        loope(i,0,z)
        {
            loope(j,0,k-2*(i))
            {
                ll te=pre[k-2*(i)]+ (v[j]+v[j+1])*i;
                if (te>ans)
                {
                    ans=te;
                }
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n+1);
        V<ll>pre(n+1);
        loop(i,0,n)
        {
            cin>>v[i];
            pre[i]=v[i];
        }
        v[n]=0;
        loop(i,1,n)
        {
            pre[i]+=pre[i-1];
        }
        ll ans=pre[k];
        loope(i,1,z)
        {
            ll te=pre[k-(2*i)];
            //cout<<pre[k-(2*i)]<<endl;
            loope(j,0,k-(2*i))
            {
                ll temp=v[j+1];
                if (j+1==n)
                {
                    temp=0;
                }
                ll te2=te+(v[j]+temp)*i;
                if (ans<te2)
                {
                    ans=te2;
                }
            }
            if (te>ans)
            {
                ans=te;
            }
        }
        if (z && k>=2)
        {
            ll te=pre[k-1];
            te+=v[k-2];
            if (te>ans)
            {
                ans=te;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        V<ll>pre(n);
        loop(i,0,n)
        {
            cin>>v[i];
            pre[i]=v[i];
        }
        loop(i,1,n)
        {
            pre[i]+=pre[i-1];
        }
        ll ans=pre[k];
        loope(i,1,z)
        {
            ll te=pre[k-(2*i)];
            //cout<<pre[k-(2*i)]<<endl;
            loope(j,0,k-(2*i))
            {
                ll te2=te+(v[j]+v[j+1])*i;
                if (ans<te2)
                {
                    ans=te2;
                }
            }
            if (te>ans)
            {
                ans=te;
            }
        }
        if (z && k>=2)
        {
            ll te=pre[k-1];
            te+=v[k-2];
            if (te>ans)
            {
                ans=te;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        ll v[n+2]={0},pre[n+2]={0};
        v[n]=0;
        cin>>pre[0];
        v[0]=pre[0];
        loop(i,1,n)
        {
            cin>>v[i];
            pre[i]=v[i]+pre[i-1];
        }
        ll ans=pre[k];
        loope(i,0,z)
        {
            loope(j,0,k-2*(i))
            {
                ll te=pre[k-2*(i)]+ (v[j]+v[j+1])*i;
                if (te>ans)
                {
                    ans=te;
                }
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        loop(i,0,n)
        {
            cin>>v[i];
        }
        ll idx=-1;
        ll mps=0;
        loop(i,0,k)
        {
            ll te=v[i]+v[i+1];
            if (te>mps)
            {
                mps=te;
                idx=i;
            }
        }
        //cout<<idx<<endl;
        ll i=0;
        ll ans=v[0];
        while(i<n)
        {
            if (k<=0)
            {
                break;
            }
            if (i!=idx)
            {
                if (!i)
                {
                    i++;
                }
                else
                {
                    ans+=v[i];
                    i++;
                    k--;
                }

            }
            else
            {
                if (idx!=0)
                {
                    ans+=v[i];
                    k--;
                }
                while(z>0)
                {
                    if (k>1)
                    {
                        ans+=mps;
                        k-=2;
                        z--;
                    }
                    else
                    {
                        break;
                    }

                }
                //cout<<ans<<endl;
                i++;
            }

        }
        cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        loop(i,0,n)
        {
            cin>>v[i];
        }
        ll idx=-1;
        ll mps=0;
        loop(i,0,k)
        {
            ll te=v[i]+v[i+1];
            if (te>mps)
            {
                mps=te;
                idx=i;
            }
        }
        //cout<<idx<<endl;
        ll i=1;
        ll ans=v[0];
        if (idx==0)
        {
            ans=v[0];
            i=0;
        }
        while(i<n)
        {
            if (k<=0)
            {
                break;
            }
            if (i!=idx)
            {
                ans+=v[i];
                i++;
                k--;
            }
            else
            {
                //cout<<ans<<endl;
                while(z>0)
                {
                    if (k>1)
                    {
                        ans+=mps;
                        k-=2;
                        z--;
                    }
                    else
                    {
                        if (k)
                        {

                            i++;
                        }
                        break;

                    }

                }
                if (!z)
                {
                    ans+=v[i];
                    i++;
                    k--;
                }

            }

        }
        cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        loop(i,0,n)
        {
            cin>>v[i];
        }
        ll idx=-1;
        ll mps=0;
        loop(i,0,k)
        {
            ll te=v[i]+v[i+1];
            if (te>mps)
            {
                mps=te;
                idx=i;
            }
        }
        //cout<<idx<<endl;
        ll i=1;
        ll ans=v[0];
        if (idx==0)
        {
            ans=v[0];
            i=0;
        }
        while(i<n)
        {
            if (k<=0)
            {
                break;
            }
            if (i!=idx)
            {
                ans+=v[i];
                i++;
                k--;
            }
            else
            {
                //cout<<ans<<endl;
                while(z>0)
                {
                    if (k>1)
                    {
                        ans+=mps;
                        k-=2;
                        z--;
                    }
                    else
                    {
                        if (k)
                        {

                            i++;
                        }
                        break;

                    }

                }
                // if (!z)
                // {
                //     ans+=v[i];
                //     i++;
                //     k--;
                // }
                i++;
            }

        }
        cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        loop(i,0,n)
        {
            cin>>v[i];
        }
        ll idx=-1;
        ll mps=0;
        loop(i,0,k)
        {
            ll te=v[i]+v[i+1];
            if (te>mps)
            {
                mps=te;
                idx=i;
            }
        }
       // cout<<idx<<endl;
        ll i=1;
        ll ans=v[0];
        while(i<n)
        {
            if (k<=0)
            {
                break;
            }
            if (i!=idx)
            {
                ans+=v[i];
                i++;
                k--;
            }
            else
            {
                //cout<<ans<<endl;
                while(z>0)
                {
                    if (k>1)
                    {
                        ans+=mps;
                        k-=2;
                        z--;
                    }
                    else
                    {
                        if (k)
                        {

                            i++;
                        }
                        break;

                    }

                }
                if (!z)
                {
                    ans+=v[i];
                    i++;
                    k--;
                }

            }

        }
        cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        V<ll>pre(n);
        loop(i,0,n)
        {
            cin>>v[i];
            pre[i]=v[i];
        }
        loop(i,1,n)
        {
            pre[i]+=pre[i-1];
        }
        ll ans=pre[k];
        loope(i,1,z)
        {
            ll te=pre[k-(2*i)];
            //cout<<pre[k-(2*i)]<<endl;
            loop(j,0,k-(2*i))
            {
                ll te2=te+(v[j]+v[j+1])*i;
                if (ans<te2)
                {
                    ans=te2;
                }
            }
            if (te>ans)
            {
                ans=te;
            }
        }
        if (z && k>=2)
        {
            ll te=pre[k-1];
            te+=v[k-2];
            if (te>ans)
            {
                ans=te;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n);
        V<ll>pre(n);
        loop(i,0,n)
        {
            cin>>v[i];
            pre[i]=v[i];
        }
        loop(i,1,n)
        {
            pre[i]+=pre[i-1];
        }
        ll ans=pre[k];
        loope(i,1,z)
        {
            ll te=pre[k-(2*i)];
            //cout<<pre[k-(2*i)]<<endl;
            loop(j,0,k-(2*i))
            {
                ll te2=te+(v[j]+v[j+1]);
                if (ans<te2)
                {
                    ans=te2;
                }
            }
            if (te>ans)
            {
                ans=te;
            }
        }
        if (z && k>=2)
        {
            ll te=pre[k-1];
            te+=v[k-2];
            if (te>ans)
            {
                ans=te;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define loope(i,a,b) for(ll i=a;i<=b;++i)
#define loopr(i,a,b) for(ll i=a;i>=b;--i)
#define loops(i,a,b,step) for(ll i=a;i<b;i+=step)
#define all(a) a.begin(),a.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define V vector
using namespace std;
typedef string str;
ll vis[55][55]={0};
ll inp[55][55];
set<pair<ll,ll>> points,point;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;
    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
void dfs(ll x,ll y,ll k,ll n)
{
    if (x<0 || y<0 || x>n-1 || y>n-1 || inp[x][y]==1 || vis[x][y]==k)
    {
        return ;
    }
    else
    {
        vis[x][y]=k;
        if (k==1)
        {
            points.insert(make_pair(x,y));
        }
        else
        {
            point.insert(make_pair(x,y));
        }
        dfs(x-1,y,k,n);
        dfs(x,y-1,k,n);
        dfs(x+1,y,k,n);
        dfs(x,y+1,k,n);
    }

}
int main ()
{
	FAST;
	//test cases
	ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,z;
        cin>>n>>k>>z;
        V<ll>v(n+1);
        V<ll>pre(n+1);
        loop(i,0,n)
        {
            cin>>v[i];
            pre[i]=v[i];
        }
        v[n]=0;
        loop(i,1,n)
        {
            pre[i]+=pre[i-1];
        }
        ll ans=pre[k];
        loope(i,1,z)
        {
            ll te=pre[k-(2*i)];
            //cout<<pre[k-(2*i)]<<endl;
            loope(j,0,k-(2*i))
            {
                ll te2=te+(v[j]+v[j+1])*i;
                if (ans<te2)
                {
                    ans=te2;
                }
            }
            if (te>ans)
            {
                ans=te;
            }
        }
        if (z && k>=2)
        {
            ll te=pre[k-1];
            te+=v[k-2];
            if (te>ans)
            {
                ans=te;
            }
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
long long solve(int i, int k, int z, bool was_left, const vector<int>& vec) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(i + 1, k - 1, z, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(i - 1, k - 1, z - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(0, k, z, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
vector<int> vec;
int solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return vec[i];
        int ans = 0;
        if (i + 1 < vec.size()) ans = vec[i] + solve(z, k - 1, i + 1, 0);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vec.resize(n);
        cin >> vec;
        cout << solve(z, k, 0, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
long long solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5) + 1];
long long solve(int i, int k, int z, bool was_left) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = max(ans, solve(z, k - 1, i + 1, 0) + a[i + 1]);
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(z, k, 1, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
long long solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return vec[i];
        long long ans = 0;
        if (i + 1 < vec.size()) ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

int a[(int)2e5 + 1], n;
map<vector<int>, long long> dp;

long long solve(int i, int k, int z, bool was_left) {
        vector<int> temp{i, k, z, was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (!k) return 0;
        if (i < n) ans = max(ans, solve(i + 1, k - 1, z, 0) + a[i + 1]);
        if (i > 1 && z && !was_left) ans = max(ans, solve(i - 1, k - 1, z - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1, k, z, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

int a[(int)2e5 + 1], n;
map<vector<int>, int> dp;

int solve(int i, int k, int z, bool was_left) {
        vector<int> temp{i, k, z, was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (!k) return 0;
        if (i < n) ans = max(ans, solve(i + 1, k - 1, z, 0) + a[i + 1]);
        if (i > 1 && z && !was_left) ans = max(ans, solve(i - 1, k - 1, z - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1, k, z, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5)];
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = solve(z, k - 1, i + 1, 0) + a[i + 1];
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << solve(z, k, 1, 0) + a[1] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
long long solve(int i, int k, int z, bool was_left, const vector<int>& vec) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(i + 1, k - 1, z, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(i - 1, k - 1, z - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(0, k, z, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
vector<int> vec;
int solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return vec[i];
        int ans = 0;
        if (i + 1 < vec.size()) ans = vec[i] + solve(z, k - 1, i + 1, 0);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vec.resize(n);
        cin >> vec;
        cout << solve(z, k, 0, 1) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

int a[(int)2e5 + 1], n;
map<vector<int>, int> dp;

int solve(int i, int k, int z, bool was_left) {
        vector<int> temp{i, k, z, was_left};
        if (dp.count(temp)) return dp[temp];
        int ans = 0;
        if (!k) return 0;
        if (i < n) ans = max(ans, solve(i + 1, k - 1, z, 0) + a[i + 1]);
        if (i > 1 && z && !was_left) ans = max(ans, solve(i - 1, k - 1, z - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1, k, z, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
long long solve(int i, int k, int z, bool was_left, const vector<int>& vec) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(i + 1, k - 1, z, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(i - 1, k - 1, z - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(0, k, z, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5) + 1];
long long solve(int i, int k, int z, bool was_left) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = max(ans, solve(z, k - 1, i + 1, 0) + a[i + 1]);
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1,k,z,0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
int solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        int ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
int solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        int ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
long long solve(int i, int k, int z, bool was_left, const vector<int>& vec) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(i + 1, k - 1, z, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(i - 1, k - 1, z - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(0, k, z, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
vector<int> vec;
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return 0;
        long long ans = 0;
        if (i + 1 < vec.size()) ans = vec[i + 1] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i - 1] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vec.resize(n);
        cin >> vec;
        cout << solve(z, k, 0, 0, vec) + vec[0] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
int solve(int i, int k, int z, bool was_left, const vector<int>& vec) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        int ans = vec[i] + solve(i + 1, k - 1, z, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(i - 1, k - 1, z - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(0, k, z, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5)];
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return 0;
        long long ans = 0;
        if (i < n) ans = solve(z, k - 1, i + 1, 0) + a[i + 1];
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i + 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << solve(z, k, 1, 0) + a[1] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
long long solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
vector<int> vec;
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return 0;
        long long ans = 0;
        if (i + 1 < vec.size()) ans = vec[i + 1] + solve(z, k - 1, i + 1, 0);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i - 1] + solve(z - 1, k - 1, i - 1, 1));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vec.resize(n);
        cin >> vec;
        cout << solve(z, k, 0, 0) + vec[0] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5) + 1];
long long solve(int i, int k, int z, bool was_left) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = max(ans, solve(i + 1, k - 1, z, 0) + a[i + 1]);
        if (!was_left && z && i > 1) ans = max(ans, solve(i - 1, k - 1, z - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1,k,z,0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
long long solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return 0;
        long long ans = 0;
        if (i + 1 < vec.size()) ans = vec[i + 1] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i - 1] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) + vec[0] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5) + 1];
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = max(ans, solve(z, k - 1, i + 1, 0) + a[i + 1]);
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(z, k, 1, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5)];
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return 0;
        long long ans = 0;
        if (i < n) ans = a[i + 1] + solve(z, k - 1, i + 1, 0);
        if (!was_left && z && i > 1) ans = max(ans, a[i - 1] + solve(z - 1, k - 1, i - 1, 1));
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << solve(z, k, 1, 0) + a[1] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
long long solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
int solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        int ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5)];
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return 0;
        long long ans = 0;
        if (i < n) ans = solve(z, k - 1, i + 1, 0) + a[i + 1];
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << solve(z, k, 1, 0) + a[1] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
int solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (k == 0) return vec[i];
        int ans = 0;
        if (i + 1 < vec.size()) ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z && i - 1 >= 0) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        dp[temp] = ans;
        return ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5) + 1];
long long solve(int z, int k, int i, bool was_left) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = max(ans, solve(z, k - 1, i + 1, 0) + a[i + 1]);
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << solve(z, k, 1, 0) + a[1] << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
//#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, int> dp;
long long solve(int z, int k, int i, bool was_left, const vector<int>& vec) {
        vector<int> temp{z, k, i, was_left};
        if (dp.count(temp)) return dp[temp];
        if (i < 0 || i >= vec.size()) return -inf;
        if (k == 0) return vec[i];
        long long ans = vec[i] + solve(z, k - 1, i + 1, 0, vec);
        if (!was_left && z) ans = max(ans, vec[i] + solve(z - 1, k - 1, i - 1, 1, vec));
        return dp[temp] = ans;
}

void _main() {
        int n, k, z; cin >> n >> k >> z;
        vector<int> vec(n); cin >> vec;
        cout << solve(z, k, 0, 0, vec) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("arch=ivybridge")
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

int a[(int)2e5 + 1], n;
map<vector<int>, int> dp;

int solve(int i, int k, int z, bool was_left) {
        vector<int> temp{i, k, z, was_left};
        if (dp.count(temp)) return dp[temp];
        int ans = 0;
        if (!k) return 0;
        if (i < n) ans = max(ans, solve(i + 1, k - 1, z, 0) + a[i + 1]);
        if (i > 1 && z && !was_left) ans = max(ans, solve(i - 1, k - 1, z - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1, k, z, 0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace::std;

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 + 5 : (int)1E18 + 5)

typedef array<int, 3> tri;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
template <class T> ostream& operator<<(ostream &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}

map<vector<int>, long long> dp;
int n;
int a[int(2e5) + 1];
long long solve(int i, int k, int z, bool was_left) {
        vector<int> temp{ i,  k,  z,  was_left};
        if (dp.count(temp)) return dp[temp];
        long long ans = 0;
        if (k == 0) return 0;
        if (i < n) ans = max(ans, solve(i + 1, ) + a[i + 1]);
        if (!was_left && z && i > 1) ans = max(ans, solve(z - 1, k - 1, i - 1, 1) + a[i - 1]);
        return dp[temp] = ans;
}

void _main() {
        int k, z; cin >> n >> k >> z;
        for (int i = 1; i <= n; i++) cin >> a[i];
        cout << a[1] + solve(1,k,z,0) << '\n';
        dp.clear();
}

#undef int
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
        cin >> _t;
        while (_t--) _main();
        return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[500010];
	stack<int> st;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		while(st.size() > 1 && a[i] >= st.top()) {
			int x = st.top();
			st.pop();
			if (x <= st.top()) {
				ans += min(st.top(), a[i]);
			} else {
				st.push(x);
				break;
			}
		}
		st.push(a[i]);
	}
	vector<int> z;
	while(st.size() != 0) {
		z.push_back(st.top());

		st.pop();
	}
	sort(z.begin(), z.end());
	for (int i = 0; i < z.size() - 2; i++) ans += z[i];
	cout << ans;
	return 0;
}


/// You just can't beat the person who never gives up
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 5e5+5 ;

int n ,a[N] ,l[N] ,r[N] ;
set<pair<int,int>> st ;
set<int> idx ;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
        l[i] = i-1 ,r[i] = i+1 ;
        st.insert({a[i],i});
        idx.insert(i);
    }
    long long ans = 0 ;
    queue<int> q ;
    while(st.size()){
        int i = st.begin()->second ;
        st.erase(st.begin()) ;
        if(i==*idx.begin() || i==*idx.rbegin()){
            idx.erase(i);
            q.push(i);
            while(q.size()>2){
                ans += a[q.front()];
                q.pop();
            }
            continue ;
        }
        auto it1 = idx.lower_bound(i) ;
        auto it2 = it1 ;
        ans += min(a[*--it1] ,a[*++it2]);
        idx.erase(i);
    }
    printf("%lld",ans);
    return 0;
}


/// You just can't beat the person who never gives up
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 5e5+5 ;

int n ,a[N] ,l[N] ,r[N] ,val[N] ;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
        l[i] = i-1 ,r[i] = i+1 ;
    }
    multiset<pair<int,int>> st ;
    for(int i=0;i<n;++i){
        if(i==0 || i+1==n) st.insert({val[i] = 0 ,i});
        else st.insert({val[i] = min(a[i-1],a[i+1]) ,i});
    }
    long long ans = 0 ;
    while(st.size()){
        auto x = *st.rbegin() ;
        if(x.first==0) break ;
        ans += x.first ;
        int i = x.second ;
        st.erase(x) ;
        if(r[i]<n){
            int j = r[i] ;
            st.erase(st.find({val[j],j}));
            l[j] = l[i] ;
            if(l[j]>=0 && r[j]<n) st.insert({val[j] = min(a[l[j]],a[r[j]]) ,j});
            else st.insert({val[j] = 0 ,j});
        }
        if(l[i]>=0){
            int j = l[i] ;
            st.erase(st.find({val[j],j}));
            r[j] = r[i] ;
            if(l[j]>=0 && r[j]<n) st.insert({val[j] = min(a[l[j]],a[r[j]]) ,j});
            else st.insert({val[j] = 0 ,j});
        }
    }
    printf("%lld",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<algorithm>

using namespace std;

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
//#define int ll

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=500000+10;

int a[MAXN],b[MAXN];

stack<int> s;

int main() {
	int n=read();
	REP(i,1,n) a[i]=read();
	int ans=0;

	REP(i,1,n) {
		while(s.size()>=2) {
			int x=s.top(),y;s.pop();
			y=s.top();
			if(y>=x&&x<=a[i])
				ans+=min(y,a[i]);
			else {
				s.push(x);
				break;
			}
		}

		s.push(a[i]);
	}

	int cnt=0;
	while(!s.empty()) {
		b[++cnt]=s.top();
		s.pop();
	}

	sort(b+1,b+1+cnt);

	REP(i,1,cnt-2) ans+=b[i];

	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<algorithm>

using namespace std;

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define int ll

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=500000+10;

int a[MAXN],b[MAXN];

stack<int> s;

signed main() {
	int n=read();
	REP(i,1,n) a[i]=read();
	int ans=0;

	REP(i,1,n) {
		while(s.size()>=2) {
			int x=s.top(),y;s.pop();
			y=s.top();
			if(y>=x&&x<=a[i])
				ans+=min(y,a[i]);
			else {
				s.push(x);
				break;
			}
		}

		s.push(a[i]);
	}

	int cnt=0;
	while(!s.empty()) {
		b[++cnt]=s.top();
		s.pop();
	}

	sort(b+1,b+1+cnt);

	REP(i,1,cnt-2) ans+=b[i];

	printf("%I64d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

const int MAXN = 500010;

int n;

int L[MAXN];
int R[MAXN];
int v[MAXN];
int ord[MAXN];

bool cmp(int i, int j) { return v[i] < v[j]; }

int main()
{
	scanf("%d",&n);

	for(int i = 1 ; i <= n ; i++)
		scanf("%d",&v[i]);

	iota( L + 1 , L + n + 1 , 0 );
	iota( R + 1 , R + n + 1 , 2 );
	iota( ord + 1 , ord + n + 1 , 1 );
	sort( ord + 1 , ord + n + 1 , cmp );

	int pL = 1;
	int pR = n;

	lli ans = 0;

	for(int i = 1 ; i <= n - 2 ; i++)
	{
		int ind = ord[i];

		if( ind == pL )
		{
			ans += v[ ind ];
			pL = R[ ind ];
		}
		else if( ind == pR )
		{
			ans += v[ ind ];
			pR = L[ ind ];
		}
		else
		{
			ans += min( v[ L[ind] ] , v[ R[ind] ] );

			R[ L[ind] ] = R[ind];
			L[ R[ind] ] = L[ind];
		}
	}

	printf("%lld\n",ans);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;

const int MAXN = 500010;

int n;

int v[MAXN];
int L[MAXN];
int R[MAXN];

set< pii > s;

int getValue(int i) { return min( v[ L[i] ], v[ R[i] ] ); }

int main()
{
    scanf("%d",&n);

    for(int i = 1 ; i <= n ; i++)
    {
        scanf("%d",&v[i]);

        L[i] = i - 1;
        R[i] = i + 1;
    }

    lli ans = 0;

    for(int i = 1 ; i <= n ; i++)
        s.insert( { -getValue( i ) , i } );

    for(int i = 1 ; i <= n ; i++)
    {
        ans -= s.begin()->first;

        int ind = s.begin()->second;
        s.erase( s.begin() );

        s.erase( { -getValue( L[ind] ) , L[ind] } );
        s.erase( { -getValue( R[ind] ) , R[ind] } );

        R[ L[ind] ] = R[ind];
        L[ R[ind] ] = L[ind];

        if( 1 <= L[ind] && L[ind] <= n ) s.insert( { -getValue( L[ind] ) , L[ind] } );
        if( 1 <= R[ind] && R[ind] <= n ) s.insert( { -getValue( R[ind] ) , R[ind] } );
    }

    printf("%lld\n",ans);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll maxn = 500010;
ll n,a[maxn],S[maxn],top,ans;

int main()
{
    scanf("%lld",&n);
    for (ll i = 1; i <= n; i++)
        scanf("%lld",&a[i]);
    for (ll i = 1; i <= n; i++)
    {
        while (top > 1 && S[top] <= S[top - 1] && S[top] <= a[i])
        {
            ans += min(S[top - 1],a[i]);
            top--;
        }
        S[++top] = a[i];
    }
    sort(S + 1,S + 1 + top);
    for (ll i = 1; i <= top - 2; i++)
        ans += S[i];
    printf("%lld\n",ans);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll maxn = 500010;
ll n,a[maxn],S[maxn],top,ans;

int main()
{
    scanf("%lld",&n);
    for (ll i = 1; i <= n; i++)
        scanf("%lld",&a[i]);
    for (ll i = 1; i <= n; i++)
    {
        while (top > 1 && S[top] < S[top - 1] && S[top] < a[i])
        {
            ans += min(S[top - 1],a[i]);
            top--;
        }
        S[++top] = a[i];
    }
    sort(S + 1,S + 1 + top);
    for (ll i = 1; i <= top - 2; i++)
        ans += S[i];
    printf("%lld\n",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[500005];
bool cmp(int x,int y)
{
	return (a[x]<a[y]);
}
int main()
{
	int n;
	scanf("%d",&n);
	vector<int> v;
	set<int> s;
	for (int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		s.insert(i);
		v.push_back(i);
	}
	sort(v.begin(),v.end(),cmp);
	long long ans=0;
	queue<int> q;
	for (int i:v)
	{
		auto it=s.find(i);
		if (it!=s.begin() && next(it)!=s.end())
		ans+=min(a[*prev(it)],a[*next(it)]);
		else
		{
			q.push(i);
			if (q.size()>2)
			{
				ans+=a[q.front()];
				q.pop();
			}
		}
		s.erase(it);
	}
	printf("%I64d",ans);
}


#include<bits/stdc++.h>
using namespace std;
int n,a[500005];
long long ans;
int main(){
	scanf("%d",&n);
	int x=-1;
	while(n--){
		x++;
		scanf("%d",&a[x]);
		while(x>=2&&a[x-1]<=min(a[x-2],a[x])){
			ans+=min(a[x-2],a[x]);
			a[x-1]=a[x];
			x--;
		}
	}
	for(int i=1;i<x;i++){
		ans+=min(a[i-1],a[i+1]);
	}
	printf("%lld",ans);
}


// You need the dark in order to show the light - Bob Ross :))
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a, ind;
long long ans = 0;
vector <int> arr;
int main() {
	cin >> n;
	if(n == 2) {
		int a, b;
		cin >> a >> b;
		cout << 0 << endl;
		return 0;
	} else if(n == 1) {
		cin >> a;
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		cin >> a;
		ind = arr.size();
		while(ind > 1 && arr[arr.size() - 1] <= a && arr[arr.size() - 1] <= arr[arr.size() - 2]) {
			ans += min(a, arr[arr.size() - 2]);
			arr.pop_back();
			ind--;
		}
		arr.push_back(a);
	}
	sort(arr.begin(), arr.end());
	for(int i = 0; i < arr.size() - 2; i++) {
		ans += arr[i];
	}
	cout << ans << endl;
	return 0;
}


// You need the dark in order to show the light - Bob Ross :))
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a, ind;
long long ans = 0;
vector <int> arr;
int main() {
	cin >> n;
	if(n == 2) {
		int a, b;
		cin >> a >> b;
		cout << 0 << endl;
		return 0;
	} else if(n == 1) {
		cin >> a;
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		cin >> a;
		ind = arr.size();
		while(ind > 1 && arr[arr.size() - 1] < a && arr[arr.size() - 1] < arr[arr.size() - 2]) {
			ans += min(a, arr[arr.size() - 2]);
			arr.pop_back();
			ind--;
		}
		arr.push_back(a);
	}
	sort(arr.begin(), arr.end());
	for(int i = 0; i < arr.size() - 2; i++) {
		ans += arr[i];
	}
	cout << ans << endl;
	return 0;
}


// You need the dark in order to show the light - Bob Ross :))
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a, ind;
long long ans = 0;
vector <int> arr;
int main() {
	cin >> n;
	if(n == 2) {
		int a, b;
		cin >> a >> b;
		cout << 0 << endl;
		return 0;
	} else if(n == 1) {
		cin >> a;
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		cin >> a;
		ind = arr.size();
		while(ind > 1 && arr[arr.size() - 1] <= a && arr[arr.size() - 1] <= arr[arr.size() - 2]) {
			ans += min(a, arr[arr.size() - 2]);
			arr.pop_back();
			ind--;
		}
		arr.push_back(a);
	}
	sort(arr.begin(), arr.end());
	for(int i = 1; i < arr.size() - 2; i++) {
		ans += arr[i];
	}
	cout << ans << endl;
	return 0;
}


// You need the dark in order to show the light - Bob Ross :))
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a, ind;
long long ans = 0;
vector <int> arr;
int main() {
	cin >> n;
	if(n == 2) {
		int a, b;
		cin >> a >> b;
		cout << 0 << endl;
		return 0;
	} else if(n == 1) {
		cin >> a;
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		cin >> a;
		ind = arr.size();
		while(ind > 1 && arr[arr.size() - 1] < a && arr[arr.size() - 1] < arr[arr.size() - 2]) {
			ans += min(a, arr[arr.size() - 2]);
			arr.pop_back();
			ind--;
		}
		arr.push_back(a);
	}
	sort(arr.begin(), arr.end() + 1);
	for(int i = 0; i < arr.size() - 2; i++) {
		ans += arr[i];
	}
	cout << ans << endl;
	return 0;
}


// https://codeforces.com/group/BG3CrODFnk/contest/272286/problem/C

#include <bits/stdc++.h>

using namespace std;

#define data blahblahblah
#define pb push_back
#define vsort(iter, comp) sort(iter.begin(), iter.end(), comp)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define put(num) cout << num << endl

typedef double bip;
typedef int64_t much;

int main(){
    int n; cin >> n;
    vector <int> data;
    much answer = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        data.pb(a);
    }
    while(data.size() != 2){
        int MAXD = 0;
        int MAXID = 0;
        for(int i = 1; i < data.size() - 1; i++){
            if(min(data[i + 1], data[i - 1]) > MAXD){
                MAXD = min(data[i + 1], data[i - 1]);
                MAXID = i;
            }
        }
        answer += MAXD;
        data.erase(data.begin() + MAXID);
    }
    put(answer);
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
const int N=5e5+5;
int n,x,l,tot,a[N],pr[N],ne[N];
pair < int , int > p[N];
ll ans;
main () {
	scanf("%d",&n);
	for (int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
		pr[i]=i-1,ne[i]=i+1;
		p[i].F=a[i],p[i].S=i;
	}

	sort(p+1,p+n+1);

	for (int i=1; i<n-1; i++) {
		x=p[i].S;
		ans+=1LL*(a[x]-l)*(n-i-1)+max(0,min(a[pr[x]],a[ne[x]])-a[x]);
		ne[pr[x]]=ne[x],pr[ne[x]]=pr[x],l=a[x];
	}

	printf("%lld\n",ans);
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define narak 998244353
#define PI 3.14159265358979323844
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define endl "\n"
#define sqr(a) (a)*(a)
#define __lcm(m,n) m*(n/__gcd(m,n))
#define inputarr(a,n) for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define display(x) for(auto &a:x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define between(n,a,b) (a<=n&&n<=b)
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<typename T, typename U> static inline void amin(T &x, U y) {
    if (y < x)
        x = y;
}

template<typename T, typename U> static inline void amax(T &x, U y) {
    if (x < y)
        x = y;
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {
    out<<a.fi<<" "<<a.se;
    return out;
}

template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {
    in>>a.fi>>a.se;
    return in;
}

inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define pii std::pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >
#define point complex<ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

using namespace std;
using namespace __gnu_pbds;

void meowmeow321()
{
    int n;
    cin>>n;
    int a[n];
    inputarr(a,n);
    set<pii> dog;
    set<int> ids;
    for (int i = 0; i < n; ++i) {
        ids.insert(i);
        dog.insert(mp(a[i],i));
    }
    ll ans=0;
    int prev=0;
    while(sz(dog)>2){
        int i=dog.begin()->se;
        ans+=(sz(dog)-2)*(a[i]-prev);
        dog.erase(dog.begin());
        prev=a[i];
        if(i==*ids.begin()||i==*(--ids.end())){
            ids.erase(i);
            continue;
        }
        ids.erase(i);
        auto it=ids.lower_bound(i);
        int wen=a[*it];
        it--;
        amin(wen,a[*it]);
        ans+=wen-prev;
    }
    cout<<ans<<endl;

}
signed main()
{
    FAST;
    int testcases=1;
    //cin>>testcases;
    for(int i=0;i<testcases;++i)
    {
        meowmeow321();
    }
    cerr<<endl<<"Time Elasped : "<<elasped_time<<endl;
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[500005];
ll nxt[500005];
ll pre[500005];
queue<ll> q;
bool vis[500005];
bool check(ll x)
{
        if(a[x] <= a[nxt[x]] && a[x] <= a[pre[x]]) return true;
        return false;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        cin >> n;
        if(n==1) {
                cout << 0 << endl; return 0;
        }
        for(ll i=1;i<=n;i++) cin >> a[i];
        a[0] = 0;
        a[n+1] = 0;
        for(ll i=0;i<=n;i++) {
                nxt[i] = i+1;
        }
        for(ll i=n+1 ; i >= 1 ; i--) {
                pre[i] = i-1;
        }
        for(ll i=1;i<=n;i++) {
                if(a[i] <= a[i+1] && a[i] <= a[i-1]) {
                        q.push(i);
                        vis[i] = true;
                }
        }
        ll ans = 0;
        while(q.empty() == false) {
                ll u = q.front();
                q.pop();
                nxt[pre[u]] = nxt[u];
                pre[nxt[u]] = pre[u];
                ans += min(a[nxt[u]] , a[pre[u]]);
                if(vis[nxt[u]] == false) {
                        if(check(nxt[u])) {
                                q.push(nxt[u]);
                                vis[nxt[u]] = true;
                        }
                }
                if(vis[pre[u]] == false) {
                        if(check(pre[u])) {
                                q.push(pre[u]);
                                vis[pre[u]] = true;
                        }
                }
        }
        vector<ll> x;
        for(ll i=1;i<=n;i++) {
                if(vis[i]==false) {
                        x.push_back(a[i]);
                }
        }
        sort(x.begin() , x.end());
        for(ll i = 0 ; i < x.size() - 2 ; i++) ans += x[i];
        cout << ans << endl;
        return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[500005];
ll nxt[500005];
ll pre[500005];
queue<ll> q;
bool vis[500005];
bool check(ll x)
{
        if(a[x] <= a[nxt[x]] && a[x] <= a[pre[x]]) return true;
        return false;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        cin >> n;
        for(ll i=1;i<=n;i++) cin >> a[i];
        a[0] = 0;
        a[n+1] = 0;
        for(ll i=0;i<=n;i++) {
                nxt[i] = i+1;
        }
        for(ll i=n+1 ; i >= 1 ; i--) {
                pre[i] = i-1;
        }
        for(ll i=1;i<=n;i++) {
                if(a[i] <= a[i+1] && a[i] <= a[i-1]) {
                        q.push(i);
                        vis[i] = true;
                }
        }
        ll ans = 0;
        while(q.empty() == false) {
                ll u = q.front();
                q.pop();
                nxt[pre[u]] = nxt[u];
                pre[nxt[u]] = pre[u];
                ans += min(a[nxt[u]] , a[pre[u]]);
                if(vis[nxt[u]] == false) {
                        if(check(nxt[u])) {
                                q.push(nxt[u]);
                                vis[nxt[u]] = true;
                        }
                }
                if(vis[pre[u]] == false) {
                        if(check(pre[u])) {
                                q.push(pre[u]);
                                vis[pre[u]] = true;
                        }
                }
        }
        vector<ll> x;
        for(ll i=1;i<=n;i++) {
                if(vis[i]==false) {
                        x.push_back(a[i]);
                }
        }
        sort(x.begin() , x.end());
        for(ll i = 0 ; i < x.size() - 2 ; i++) ans += x[i];
        cout << ans << endl;
        return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll
#define F first
#define S second

const int N = 5e5 + 10;
const int INF = 1e9 + 10;
pair<int, int> t[N];
int L[N], R[N], a[N], n;

void build(int v, int l, int r) {
	if (l == r) {
		t[v] = {a[l], l};
		return;
	}
	int mid = (l + r) / 2;
	build(2 * v, l, mid);
	build(2 * v + 1, mid + 1, r);
	t[v] = min(t[2 * v], t[2 * v + 1]);
}

void update(int v, int l, int r, int need) {
	if (l == r) {
		t[v] = {INF, 0};
		return;
	}
	int mid = (l + r) / 2;
	if (need <= mid) {
		update(2 * v, l, mid, need);
	}
	else {
		update(2 * v + 1, mid + 1, r, need);
	}
	t[v] = min(t[2 * v], t[2 * v + 1]);
}

pair<int, int> get(int v, int l, int r, int a, int b) {
	if (l > b || r < a) {
		return {INF, 0};
	}
	if (l >= a && r <= b) {
		return t[v];
	}
	int mid = (l + r) / 2;
	return min(get(2 * v, l, mid, a, b), get(2 * v + 1, mid + 1, r, a, b));
}

int solve(int l, int r) {
	// /cout << l << ' ' << r << '\n';
	pair<int, int> k1 = get(1, 1, n, l, r), k2 = get(1, 1, n, l + 1, r - 1);
	if (k2.F == INF) {
		return 0;
	}
	/cout << k1.F << ' ' << k1.S << '\n';
	if (k2.F == k1.F) {
		int A = L[k2.S], B = R[k2.S];
		int vl = min(a[A], a[B]);
		update(1, 1, n, k2.S);
		L[B] = A;
		R[A] = B;
		return vl + solve(l, r);
	}
	if (a[l] == k1.F) {
		return k1.F + solve(R[l], r);
	}
	return k1.F + solve(l, L[r]);
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		L[i] = i - 1;
		R[i] = i + 1;
	}
	build(1, 1, n);
	cout << solve(1, n) << '\n';
	cerr << "TIME :: " << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll
#define F first
#define S second

const int N = 5e5 + 10;
const int INF = 1e9 + 10;
pair<int, int> t[N];
int L[N], R[N], a[N], n;

void build(int v, int l, int r) {
	if (l == r) {
		t[v] = {a[l], l};
		return;
	}
	int mid = (l + r) / 2;
	build(2 * v, l, mid);
	build(2 * v + 1, mid + 1, r);
	t[v] = min(t[2 * v], t[2 * v + 1]);
}

void update(int v, int l, int r, int need) {
	if (l == r) {
		t[v] = {INF, 0};
		return;
	}
	int mid = (l + r) / 2;
	if (need <= mid) {
		update(2 * v, l, mid, need);
	}
	else {
		update(2 * v + 1, mid + 1, r, need);
	}
	t[v] = min(t[2 * v], t[2 * v + 1]);
}

pair<int, int> get(int v, int l, int r, int a, int b) {
	if (l > b || r < a) {
		return {INF, 0};
	}
	if (l >= a && r <= b) {
		return t[v];
	}
	int mid = (l + r) / 2;
	return min(get(2 * v, l, mid, a, b), get(2 * v + 1, mid + 1, r, a, b));
}

int solve(int l, int r) {
	// /cout << l << ' ' << r << '\n';
	pair<int, int> k1 = get(1, 1, n, l, r), k2 = get(1, 1, n, l + 1, r - 1);
	if (k2.F == INF) {
		return 0;
	}
	///cout << k1.F << ' ' << k1.S << '\n';
	if (k2.F == k1.F) {
		int A = L[k2.S], B = R[k2.S];
		int vl = min(a[A], a[B]);
		update(1, 1, n, k2.S);
		L[B] = A;
		R[A] = B;
		return vl + solve(l, r);
	}
	if (a[l] == k1.F) {
		return k1.F + solve(R[l], r);
	}
	return k1.F + solve(l, L[r]);
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		L[i] = i - 1;
		R[i] = i + 1;
	}
	build(1, 1, n);
	cout << solve(1, n) << '\n';
	cerr << "TIME :: " << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll
#define F first
#define S second

const int N = 5e5 + 10;
const int INF = 1e9 + 10;
pair<int, int> t[4 * N];
int L[N], R[N], a[N], n;

void build(int v, int l, int r) {
	if (l == r) {
		t[v] = {a[l], l};
		return;
	}
	int mid = (l + r) / 2;
	build(2 * v, l, mid);
	build(2 * v + 1, mid + 1, r);
	t[v] = min(t[2 * v], t[2 * v + 1]);
}

void update(int v, int l, int r, int need) {
	if (l == r) {
		t[v] = {INF, 0};
		return;
	}
	int mid = (l + r) / 2;
	if (need <= mid) {
		update(2 * v, l, mid, need);
	}
	else {
		update(2 * v + 1, mid + 1, r, need);
	}
	t[v] = min(t[2 * v], t[2 * v + 1]);
}

pair<int, int> get(int v, int l, int r, int a, int b) {
	if (l > b || r < a) {
		return {INF, 0};
	}
	if (l >= a && r <= b) {
		return t[v];
	}
	int mid = (l + r) / 2;
	return min(get(2 * v, l, mid, a, b), get(2 * v + 1, mid + 1, r, a, b));
}

int solve(int l, int r) {
	// /cout << l << ' ' << r << '\n';
	pair<int, int> k1 = get(1, 1, n, l, r), k2 = get(1, 1, n, l + 1, r - 1);
	if (k2.F == INF) {
		return 0;
	}
	//cout << k1.F << ' ' << k1.S << '\n';
	if (k2.F == k1.F) {
		int A = L[k2.S], B = R[k2.S];
		int vl = min(a[A], a[B]);
		update(1, 1, n, k2.S);
		L[B] = A;
		R[A] = B;
		return vl + solve(l, r);
	}
	if (a[l] == k1.F) {
		return k1.F + solve(R[l], r);
	}
	return k1.F + solve(l, L[r]);
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		L[i] = i - 1;
		R[i] = i + 1;
	}
	build(1, 1, n);
	cout << solve(1, n) << '\n';
	cerr << "TIME :: " << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
}