我们枚举cnt 暴力 a,b
#include <bits/stdc++.h>
using namespace std;
#define int long long
//typedef long long ll;
typedef pair<int,int> pii;
#define x first
#define y second
#define pb push_back
#define inf 1e18
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define der(i,a,b) for(int i=a;i>=b;i--)
const int maxn=1e5+10;
const int mod=1e9+7;
/*ll qsm(int a,int b)
{ll res=1; while(b){ if(b&1) res=res*a%mod; a=a*a%mod; b>>=1; } return res;}*/
const int N=3e5+10;
int dr[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int n,k;
int a[N];
int m;
vector<int>cnt[N];
void solve()
{ map<int,int>mp;
map<pii,bool>mp2;
vector<int>v;
cin>>n>>m;
fer(i,1,n)
{
cin>>a[i];
mp[a[i]]++;
}
fer(i,1,m)
{
int x,y;
cin>>x>>y;
mp2[{x,y}]=1;
mp2[{y,x}]=1;
}
int mx=0;
for(auto it:mp)
{
if(cnt[it.y].empty())
{
v.pb(it.y);
}
cnt[it.y].pb(it.x);
}
fer(i,1,n)sort(cnt[i].begin(),cnt[i].end(),greater<int>());
for(int i=0;i<v.size();i++)
{
for(int j=i;j<v.size();j++)
{
bool f=0;
int t=0;
for(auto it1:cnt[v[j]])
{
for(auto it2:cnt[v[i]])
{
if((it1+it2)*(v[i]+v[j])<=mx)break;;
if(i==j&&it2==it1)continue;
if(mp2[{it1,it2}])continue;
if((it1+it2)*(v[i]+v[j])>mx)
{
mx=(it1+it2)*(v[i]+v[j]);
}
break;
}
}
}
}
cout<<mx<<endl;fer(i,1,n)cnt[i].clear();
}
signed main()
{
IOS;
int _;
cin>>_;
while(_--) solve();
return 0;
}