#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <climits>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <iomanip>
#define ALL(v) v.begin(), v.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REPD(i, a, b) for(int i = a; i > b; i--)
#define REPLL(i, a, b) for(ll i = a; i < b; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define FORLL(i, a, b) for(ll i = a; i <= b; i++)
#define INF 1000000001
#define vit vector<int>::iterator
#define sit set<int>::iterator
#define vi vector<int>
#define vpii vector<pii >
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pld pair<ld, ld>
#define st first
#define nd second
#define EPS 1e-9
#define PI acos(-1.0)
#define MAXN 40
using namespace std;
int z, n, m, a, b;
int gold[MAXN];
vi nbs[MAXN];
vi nbsf[MAXN];
int dist[MAXN];
vi ls[MAXN];
int layers;
int cl[MAXN];
int vis[MAXN];
int mark[MAXN];
int ret, x;
void bfs() {
queue<int> q;
q.push(0);
REP(i, 0, n) dist[i] = INF;
dist[0] = 0;
while(q.size()) {
int c = q.front(); q.pop();
ls[dist[c]].pb(c);
REP(i, 0, nbs[c].size()) {
int nb = nbs[c][i];
if(dist[nb] == INF) {
dist[nb] = dist[c] + 1;
q.push(nb);
}
}
}
layers = dist[1];
cl[layers] = 1;
cl[0] = 0;
}
int dfs_back(int v) {
if(v == 0) return 1;
if(vis[v]++) return 0;
if(mark[v]) return 0;
REP(i, 0, nbs[v].size()) {
if(dfs_back(nbs[v][i])) return 1;
}
return 0;
}
void fl(int layer, int cur, int bag) {
if(layer == layers) {
if(cur == 1 && bag > ret) {
memset(vis, 0, sizeof vis);
if(dfs_back(1)) {
//FOR(i, 0, layers) cout << cl[i] << " "; cout << endl;
ret = max(ret, bag);
}
}
return;
}
REP(i, 0, nbsf[cur].size()) {
int nxt = nbsf[cur][i];
mark[nxt] = 1;
cl[layer+1] = nxt;
bag += gold[nxt];
fl(layer+1, nxt, bag);
mark[nxt] = 0;
cl[layer+1] = -1;
bag -= gold[nxt];
fl(layer+1, nxt, bag);
}
}
int main()
{
scanf("%d", &z); z++;
while(z-- > 1) {
scanf("%d%d", &n, &m);
ret = 0;
FOR(i, 0, n) {
nbs[i].clear();
nbsf[i].clear();
ls[i].clear();
}
memset(cl, -1, sizeof cl);
memset(mark, 0, sizeof mark);
memset(vis, 0, sizeof vis);
REP(i, 2, n) scanf("%d", &gold[i]);
REP(i, 0, m) {
scanf("%d%d", &a, &b);
--a; --b;
nbs[a].pb(b);
nbs[b].pb(a);
}
bfs();
REP(i, 0, n) {
REP(j, 0, (int)nbs[i].size()) {
int nb = nbs[i][j];
}
REP(j, 0, (int)nbs[i].size()) {
int nb = nbs[i][j];
if(dist[nb] > dist[i]) nbsf[i].pb(nb);
}
}
fl(0, 0, 0);
printf("%d\n", ret);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8Y2xpbWl0cz4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgoKI2RlZmluZSBBTEwodikgdi5iZWdpbigpLCB2LmVuZCgpCiNkZWZpbmUgUkVQKGksIGEsIGIpIGZvcihpbnQgaSA9IGE7IGkgPCBiOyBpKyspCiNkZWZpbmUgUkVQRChpL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cTsKICAgIHEucHVzaCgwKTsKICAgIFJFUChpLCAwLCBuKSBkaXN0W2ldID0gSU5GOwogICAgZGlzdFswXSA9IDA7CiAgICB3aGlsZShxLnNpemUoKSkgewogICAgICAgIGludCBjID0gcS5mcm9udCgpOyBxLnBvcCgpOwogICAgICAgIGxzW2Rpc3RbY11dLnBiKGMpOwogICAgICAgIFJFUChpLCAwLCBuYnNbY10uc2l6ZSgpKSB7CiAgICAgICAgICAgIGludCBuYiA9IG5ic1tjXVtpXTsKICAgICAgICAgICAgaWYoZGlzdFtuYl0gPT0gSU5GKSB7CiAgICAgICAgICAgICAgICBkaXN0W25iXSA9IGRpc3RbY10gKyAxOwogICAgICAgICAgICAgICAgcS5wdXNoKG5iKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGxheWVycyA9IGRpc3RbMV07CiAgICBjbFtsYXllcnNdID0gMTsKICAgIGNsWzBdID0gMDsKfQoKaW50IGRmc19iYWNrKGludCB2KSB7CiAgICBpZih2ID09IDApIHJldHVybiAxOwogICAgaWYodmlzW3ZdKyspIHJldHVybiAwOwogICAgaWYobWFya1t2XSkgcmV0dXJuIDA7CiAgICBSRVAoaSwgMCwgbmJzW3ZdLnNpemUoKSkgewogICAgICAgIGlmKGRmc19iYWNrKG5ic1t2XVtpXSkpIHJldHVybiAxOwogICAgfQogICAgcmV0dXJuIDA7Cn0KCnZvaWQgZmwoaW50IGxheWVyLCBpbnQgY3VyLCBpbnQgYmFnKSB7CiAgICBpZihsYXllciA9PSBsYXllcnMpIHsKICAgICAgICBpZihjdXIgPT0gMSAmJiBiYWcgPiByZXQpIHsKICAgICAgICAgICAgbWVtc2V0KHZpcywgMCwgc2l6ZW9mIHZpcyk7CiAgICAgICAgICAgIGlmKGRmc19iYWNrKDEpKSB7CiAgICAgICAgICAgICAgICAvL0ZPUihpLCAwLCBsYXllcnMpIGNvdXQgPDwgY2xbaV0gPDwgIiAiOyBjb3V0IDw8IGVuZGw7CiAgICAgICAgICAgICAgICByZXQgPSBtYXgocmV0LCBiYWcpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybjsKICAgIH0KICAgIFJFUChpLCAwLCBuYnNmW2N1cl0uc2l6ZSgpKSB7CiAgICAgICAgaW50IG54dCA9IG5ic2ZbY3VyXVtpXTsKICAgICAgICBtYXJrW254dF0gPSAxOwogICAgICAgIGNsW2xheWVyKzFdID0gbnh0OwogICAgICAgIGJhZyArPSBnb2xkW254dF07CiAgICAgICAgZmwobGF5ZXIrMSwgbnh0LCBiYWcpOwogICAgICAgIG1hcmtbbnh0XSA9IDA7CiAgICAgICAgY2xbbGF5ZXIrMV0gPSAtMTsKICAgICAgICBiYWcgLT0gZ29sZFtueHRdOwogICAgICAgIGZsKGxheWVyKzEsIG54dCwgYmFnKTsKICAgIH0KfQoKaW50IG1haW4oKQp7CglzY2FuZigiJWQiLCAmeik7IHorKzsKCgl3aGlsZSh6LS0gPiAxKSB7CiAgICAgICAgc2NhbmYoIiVkJWQiLCAmbiwgJm0pOwogICAgICAgIHJldCA9IDA7CiAgICAgICAgRk9SKGksIDAsIG4pIHsKICAgICAgICAgICAgbmJzW2ldLmNsZWFyKCk7CiAgICAgICAgICAgIG5ic2ZbaV0uY2xlYXIoKTsKICAgICAgICAgICAgbHNbaV0uY2xlYXIoKTsKICAgICAgICB9CiAgICAgICAgbWVtc2V0KGNsLCAtMSwgc2l6ZW9mIGNsKTsKICAgICAgICBtZW1zZXQobWFyaywgMCwgc2l6ZW9mIG1hcmspOwogICAgICAgIG1lbXNldCh2aXMsIDAsIHNpemVvZiB2aXMpOwoKICAgICAgICBSRVAoaSwgMiwgbikgc2NhbmYoIiVkIiwgJmdvbGRbaV0pOwogICAgICAgIFJFUChpLCAwLCBtKSB7CiAgICAgICAgICAgIHNjYW5mKCIlZCVkIiwgJmEsICZiKTsKICAgICAgICAgICAgLS1hOyAtLWI7CiAgICAgICAgICAgIG5ic1thXS5wYihiKTsKICAgICAgICAgICAgbmJzW2JdLnBiKGEpOwogICAgICAgIH0KICAgICAgICBiZnMoKTsKICAgICAgICBSRVAoaSwgMCwgbikgewogICAgICAgICAgICBSRVAoaiwgMCwgKGludCluYnNbaV0uc2l6ZSgpKSB7CiAgICAgICAgICAgICAgICBpbnQgbmIgPSBuYnNbaV1bal07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgUkVQKGosIDAsIChpbnQpbmJzW2ldLnNpemUoKSkgewogICAgICAgICAgICAgICAgaW50IG5iID0gbmJzW2ldW2pdOwogICAgICAgICAgICAgICAgaWYoZGlzdFtuYl0gPiBkaXN0W2ldKSBuYnNmW2ldLnBiKG5iKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmbCgwLCAwLCAwKTsKICAgICAgICBwcmludGYoIiVkXG4iLCByZXQpOwoJfQoKICAgIHJldHVybiAwOwp9CgoK