#include<iostream> #include<cstring> #include<cstdio> #include<queue> #define ll long long #define N 50005 #define INF (1LL<<60) using namespace std; struct Node{ int v,next,value; }node[N*2]; int cnt; int head[N]; bool visit[N]; ll dis[N]; void add(int a,int b,int c){ node[cnt].value = c; node[cnt].v = b; node[cnt].next = head[a]; head[a] = cnt++; } bool spfa(int n){ for(int i=1;i<=n;i++){ visit[i] = 0; dis[i] = INF; } visit[1] = 1; dis[1] = 0; queue<int>q; q.push(1); while(!q.empty()){ int u = q.front(); q.pop(); for(int i=head[u];i!=-1;i=node[i].next){ int v = node[i].v; if(dis[v]>dis[u]+node[i].value){ dis[v] = dis[u]+node[i].value; if(visit[v]==0){ visit[v] = 1; q.push(v); } } } visit[u] = 0; } for(int i=1;i<=n;i++){ if(dis[i]==INF){ return false; } } return true; } int main(){ int t,v,e,a,b,c; ll ans; int w[N]; scanf("%d",&t); while(t--){ scanf("%d%d",&v,&e); for(int i=1;i<=v;i++){ scanf("%d",&w[i]); } cnt = 0; memset(head,-1,sizeof head); for(int i=1;i<=e;i++){ scanf("%d%d%d",&a,&b,&c); add(a,b,c); add(b,a,c); } if(!spfa(v)){ printf("No Answer\n"); continue; } else{ ans = 0; for(int i=1;i<=v;i++){ ans += dis[i]*w[i]; } printf("%lld\n",ans); } } return 0; }