#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <utility>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define PB push_back
#define int long long
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#ifdef LOCAL
#define debug(x) {cerr <<#x <<" = " <<x <<"\n"; }
#define debug2(x, y) {cerr <<#x <<" = " <<x <<", "<<#y <<" = " <<y <<"\n";}
#define debug3(x, y, z) {cerr <<#x <<" = " <<x <<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
using std::cerr;
#else
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define debugv(x)
#define cerr if(0)cout
#endif
#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
using std::endl;
using std::cout;
using std::cin;
using std::vector;
using std::set;
using std::map;
using std::pair;
using std::max;
using std::min;
using std::ostream;
using std::fixed;
using std::ios_base;
using std::setprecision;
using std::make_pair;
using std::string;
using std::multiset;
using std::next_permutation;
using std::prev_permutation;
using std::random_shuffle;
using std::greater;
using std::lower_bound;
using std::upper_bound;
using std::reverse;
using std::swap;
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
const int N = 44;
const int INF = 1e7;
int dis[N][N];
int lay[N];
int best_in_lay[N];
int suf[N];
int val[N];
int best = 0;
vector<int> layers[N];
bool cmp(int a, int b) {
return val[a] > val[b];
}
int vis[N];
int taken[N];
vector<int> slo[N];
bool Dfs(int v) {
vis[v] = 1;
if (v == 2) {
return true;
}
for (auto nei : slo[v]) {
if (vis[nei] || taken[nei]) {
continue;
}
if (Dfs(nei)) {
return true;
}
}
return false;
}
void Rec(int layer, int last_v, int act_val) {
if (best >= act_val + suf[layer]) {
return;
}
if (layer == lay[2]) {
if (dis[2][last_v] != layer - lay[last_v]) {
return;
}
RE (i, N - 2) {
vis[i] = 0;
}
if (Dfs(1)) {
maxi(best, act_val);
}
return;
}
for (int v : layers[layer]) {
if (dis[v][last_v] != layer - lay[last_v]) {
continue;
} else {
taken[v] = 1;
Rec(layer + 1, v, act_val + val[v]);
taken[v] = 0;
}
}
Rec(layer + 1, last_v, act_val);
}
#undef int
int main() {
#define int long long
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(10);
double beg = 1.0 * clock() / CLOCKS_PER_SEC;
make(int, t);
RE (tt, t) {
make2(int, n, m);
FOR (i, 3, n) {
cin>>val[i];
}
RE (i, n) {
RE (j, n) {
dis[i][j] = N;
}
dis[i][i] = 0;
slo[i].clear();
}
RE (i, m) {
make2(int, a, b);
dis[a][b] = dis[b][a] = 1;
slo[a].PB(b);
slo[b].PB(a);
}
RE (k, n) {
RE (i, n) {
RE (j, n) {
mini(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
REP (i, N) {
layers[i].clear();
}
RE (i, n) {
lay[i] = dis[1][i];
layers[lay[i]].PB(i);
}
FORD (i, n, 0) {
sort(layers[i].begin(), layers[i].end(), cmp);
if (SZ(layers[i])) {
suf[i] = suf[i + 1] + val[layers[i][0]];
}
}
//was.clear();
best = 0;
//dfs1(0, 1, 0, vector<int>{1});
Rec(0, 1, 0);
cout<<best<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGFzc2VydC5oPgojZGVmaW5lIE1QIG1ha2VfcGFpcgojZGVmaW5lIFBCIHB1c2hfYmFjawojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBGT1IoaSwgYSwgYikgZm9yKGludCBpID0oYSk7IGkgPD0oYik7ICsraSkKI2RlZmluZSBSRShpLCBuKSBGT1IoaSwgMSwgbikKI2RlZmluZSBGT1JEKGksIGEsIGIpIGZvcihpbnQgaSA9IChhKTsgaSA+PSAoYik7IC0taSkKI2RlZmluZSBSRVAoaSwgbikgZm9yKGludCBpID0gMDtpIDwobik7ICsraSkKI2RlZmluZSBWQVIodiwgaSkgX190eXBlb2YoaSkgdj0oaSkKI2RlZmluZSBGT1JFKGksIGMpIGZvcihWQVIoaSwgKGMpLmJlZ2luKCkpOyBpICE9IChjKS5lbmQoKTsgKytpKQojZGVmaW5lIEFMTCh4KSAoeCkuYmVnaW4oKSwgKHgpLmVuZCgpCiNkZWZpbmUgU1ooeCkgKChpbnQpKHgpLnNpemUoKSkKI2lmZGVmIExPQ0FMCiNkZWZpbmUgZGVidWcoeCkge2NlcnIgPDwjeCA8PCIgPSAiIDw8eCA8PCJcbiI7IH0KI2RlZmluZSBkZWJ1ZzIoeCwgeS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0IGludCBOID0gNDQ7CmNvbnN0IGludCBJTkYgPSAxZTc7CmludCBkaXNbTl1bTl07CmludCBsYXlbTl07CmludCBiZXN0X2luX2xheVtOXTsKaW50IHN1ZltOXTsKaW50IHZhbFtOXTsKaW50IGJlc3QgPSAwOwp2ZWN0b3I8aW50PiBsYXllcnNbTl07CmJvb2wgY21wKGludCBhLCBpbnQgYikgewogIHJldHVybiB2YWxbYV0gPiB2YWxbYl07Cn0KaW50IHZpc1tOXTsKaW50IHRha2VuW05dOwp2ZWN0b3I8aW50PiBzbG9bTl07CmJvb2wgRGZzKGludCB2KSB7CiAgdmlzW3ZdID0gMTsKICBpZiAodiA9PSAyKSB7CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZm9yIChhdXRvIG5laSA6IHNsb1t2XSkgewogICAgaWYgKHZpc1tuZWldIHx8IHRha2VuW25laV0pIHsKICAgICAgY29udGludWU7CiAgICB9CiAgICBpZiAoRGZzKG5laSkpIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgfQogIHJldHVybiBmYWxzZTsKfQoKdm9pZCBSZWMoaW50IGxheWVyLCBpbnQgbGFzdF92LCBpbnQgYWN0X3ZhbCkgewogIGlmIChiZXN0ID49IGFjdF92YWwgKyBzdWZbbGF5ZXJdKSB7CiAgICByZXR1cm47CiAgfQogIGlmIChsYXllciA9PSBsYXlbMl0pIHsKICAgIGlmIChkaXNbMl1bbGFzdF92XSAhPSBsYXllciAtIGxheVtsYXN0X3ZdKSB7CiAgICAgIHJldHVybjsKICAgIH0KICAgIFJFIChpLCBOIC0gMikgewogICAgICB2aXNbaV0gPSAwOwogICAgfQogICAgaWYgKERmcygxKSkgewogICAgICBtYXhpKGJlc3QsIGFjdF92YWwpOwogICAgfQogICAgcmV0dXJuOwogIH0KICBmb3IgKGludCB2IDogbGF5ZXJzW2xheWVyXSkgewogICAgaWYgKGRpc1t2XVtsYXN0X3ZdICE9IGxheWVyIC0gbGF5W2xhc3Rfdl0pIHsKICAgICAgY29udGludWU7CiAgICB9IGVsc2UgewogICAgICB0YWtlblt2XSA9IDE7CiAgICAgIFJlYyhsYXllciArIDEsIHYsIGFjdF92YWwgKyB2YWxbdl0pOwogICAgICB0YWtlblt2XSA9IDA7CiAgICB9CiAgfQogIFJlYyhsYXllciArIDEsIGxhc3RfdiwgYWN0X3ZhbCk7Cn0KICAgIAogICAgICAKCiN1bmRlZiBpbnQKaW50IG1haW4oKSB7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogIGNvdXQgPDwgZml4ZWQgPDwgc2V0cHJlY2lzaW9uKDEwKTsKICBkb3VibGUgYmVnID0gMS4wICogY2xvY2soKSAvIENMT0NLU19QRVJfU0VDOwogIAogIG1ha2UoaW50LCB0KTsKICBSRSAodHQsIHQpIHsKICAgIG1ha2UyKGludCwgbiwgbSk7CiAgICBGT1IgKGksIDMsIG4pIHsKICAgICAgY2luPj52YWxbaV07CiAgICB9CiAgICBSRSAoaSwgbikgewogICAgICBSRSAoaiwgbikgewogICAgICAgIGRpc1tpXVtqXSA9IE47CiAgICAgIH0KICAgICAgZGlzW2ldW2ldID0gMDsKICAgICAgc2xvW2ldLmNsZWFyKCk7CiAgICB9CiAgICBSRSAoaSwgbSkgewogICAgICBtYWtlMihpbnQsIGEsIGIpOwogICAgICBkaXNbYV1bYl0gPSBkaXNbYl1bYV0gPSAxOwogICAgICBzbG9bYV0uUEIoYik7CiAgICAgIHNsb1tiXS5QQihhKTsKICAgIH0KICAgIFJFIChrLCBuKSB7CiAgICAgIFJFIChpLCBuKSB7CiAgICAgICAgUkUgKGosIG4pIHsKICAgICAgICAgIG1pbmkoZGlzW2ldW2pdLCBkaXNbaV1ba10gKyBkaXNba11bal0pOwogICAgICAgIH0KICAgICAgfQogICAgfQogICAgCiAgICBSRVAgKGksIE4pIHsKICAgICAgbGF5ZXJzW2ldLmNsZWFyKCk7CiAgICB9CiAgICAKICAgIFJFIChpLCBuKSB7CiAgICAgIGxheVtpXSA9IGRpc1sxXVtpXTsKICAgICAgbGF5ZXJzW2xheVtpXV0uUEIoaSk7CiAgICB9CiAgICAKICAgIEZPUkQgKGksIG4sIDApIHsKICAgICAgc29ydChsYXllcnNbaV0uYmVnaW4oKSwgbGF5ZXJzW2ldLmVuZCgpLCBjbXApOwogICAgICBpZiAoU1oobGF5ZXJzW2ldKSkgewogICAgICAgIHN1ZltpXSA9IHN1ZltpICsgMV0gKyB2YWxbbGF5ZXJzW2ldWzBdXTsKICAgICAgfQogICAgfQogICAgCiAgICAvL3dhcy5jbGVhcigpOwogICAgYmVzdCA9IDA7CiAgICAvL2RmczEoMCwgMSwgMCwgdmVjdG9yPGludD57MX0pOwogICAgUmVjKDAsIDEsIDApOwogICAgY291dDw8YmVzdDw8ZW5kbDsKICB9CgogIHJldHVybiAwOwp9Cg==