#include "stdio.h"
#include "conio.h"
#include "iostream"
#define max 500
using namespace std;
int sobotest;
int n,m,k,s,t,a[500][500],vitrii,vitrij,nhonhat;
int DijkTuan(int ab[500][500], int S,int F){
int min,u,v,free[500],dt[500];
for(u=1;u<=n;u++){
free[u]=1;
dt[u]=max;
}
dt[S]=0;
do{
u=0;min=max;
for(v=1;v<=n;v++){
if(dt[v]<min&&free[v]) min=dt[v],u=v;
}
if(u==0||u==F) break;
free[u]=0;
for(v=1;v<=n;v++)
if(ab[u][v]!=0&&free[v]&&dt[v]>dt[u]+ab[u][v])
dt[v]=dt[u]+ab[u][v];
}while(1);
return dt[F];
}
void docfile(FILE *f)
{
fscanf(f,"%d",&sobotest);
printf("%d",sobotest);
for(int i=0;i<sobotest;i++)
{
memset(a,0,sizeof(a));
fscanf(f,"%d",&n);
fscanf(f,"%d",&m);
fscanf(f,"%d",&k);
fscanf(f,"%d",&s);
fscanf(f,"%d",&t);
for(int i=1;i<=m;i++)
{
fscanf(f,"%d",&vitrii);
fscanf(f,"%d",&vitrij);
fscanf(f,"%d",&a[vitrii][vitrij]);
}
nhonhat=DijkTuan(a,s,t);
printf("\n %3d\n",nhonhat);
for(int i=1;i<=k;i++)
{
fscanf(f,"%d",&vitrii);
fscanf(f,"%d",&vitrij);
int tam1=a[vitrii][vitrij];
int tam2=a[vitrij][vitrii];
int xuli;
fscanf(f,"%d",&xuli);
a[vitrii][vitrij]=xuli;
a[vitrij][vitrii]=xuli;
int DijTam=DijkTuan(a,s,t);
if(DijTam<nhonhat)
{
nhonhat=DijTam;
}
a[vitrii][vitrij]=tam1;
a[vitrij][vitrii]=tam2;
}
printf("\n %3d\n",nhonhat);
}
}
int main()
{
int thoa=5000;
FILE *f;
char *name="D:\\Sample.INP";
f=fopen(name,"rt");
docfile(f);
getch();
return 0;
}