#include<bits/stdc++.h>
using namespace std;
#define PLL pair<long long,long long>
#define fi first
#define se second
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
stack<PLL> s;
long long res1=0;
for(int i=1;i<=n;i++)
{
long long x;
scanf("%lld",&x);
if(s.empty()||s.top().fi<=x) s.push({x,1});
else
{
long long cnt=0;
while(s.size()&&s.top().fi>x)
{
PLL nw=s.top();
cnt+=nw.se;
s.pop();
if(res1<=nw.fi*cnt) res1=nw.fi*cnt;
}
s.push({x,cnt+1});//一定要加+1!!!!
}
}
long long cnt=0;
while(s.size())
{
PLL nw=s.top();
cnt+=nw.se;
s.pop();
if(res1<=nw.fi*cnt) res1=nw.fi*cnt;
}
printf("%lld\n",res1);
}
return 0 - 0;
}