没啥好说的...
//
// Created by xingchaoyue on 2019/5/16.
//
#include<iostream>
#include<cstdio>
#include<queue>
#include<string.h>
using namespace std;
int n,m;
int mp[1005][1005];
int a[2000];
int st,ed;
int dist[2000];
const int inf = 0x3f3f3f3f;
int vis[2000];
struct node{
int tim;
int pos;
bool operator < (const node &a)const{
return tim>a.tim;
}
node(int _tim, int _pos):tim(_tim),pos(_pos){}
};
void dijist(int st){
for(int i =1;i<=n;++i){
dist[i] = inf;
vis[i] = 0;
}
dist[st] = 0;
node temp(0,st);
priority_queue<node>q;
q.push(temp);
while(!q.empty()){
node t = q.top();
q.pop();
int tim = t.tim;
int u = t.pos;
// cout<<u<<endl;
//cout<<tim<<endl;
if(vis[u])continue;
if(u==ed)break;
vis[u]=1;
int x = tim/a[u];
int now = tim;
if(x%2==1)
now = (x+1)*a[u];
dist[u] = now;
for(int i =1;i<=n;++i){
if(!vis[i]&&dist[i]>dist[u]+mp[u][i]){
dist[i] = dist[u]+mp[u][i];
// cout<<u<<":"<<i<<":"<<dist[i]<<endl;
node te(dist[i],i);
q.push(te);
}
}
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(mp,0,sizeof(mp));
scanf("%d%d",&n,&m);
for(int i =1;i<=n;++i){
scanf("%d",&a[i]);
}
for(int i =1;i<=m;++i){
int x,y,w;
scanf("%d%d%d",&x,&y,&w);
mp[x][y] = w;
mp[y][x] = w;
}
for(int i =1;i<=n;++i){
for(int j =1;j<=n;++j){
if(!mp[i][j])
mp[i][j]=inf;
}
}
scanf("%d%d",&st,&ed);
dijist(st);
cout<<dist[ed]<<endl;
}
}