#include<bits/stdc++.h>
#define INF 99999999
using namespace std;
int graph[105][105];
void init()
{
for(int i=1; i<=102; i++)
{
for(int j=1; j<=102; j++)
{
if(i==j)
graph[i][j] = 0;
else
graph[i][j] = INF;
}
}
}
int main()
{
int test;
scanf("%d", &test);
for(int cs = 1; cs<=test; cs++)
{
init();
int node, edge, u, v, cost;
scanf("%d %d", &node, &edge);
for(int i=0; i<edge; i++)
{
scanf("%d %d %d", &u, &v, &cost);
graph[u][v] = graph[v][u] = min(cost, graph[u][v]);
}
for(int k=1; k<=node; k++)
{
for(int i=1; i<=node; i++)
{
for(int j=1; j<=node; j++)
{
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
/*for(int i=1; i<=node; i++)
{
for(int j=1; j<=node; j++)
{
printf("%d ", graph[i][j]);
}
printf("\n");
}*/
int cntdup = 0, mindis = INF, mini = INF;
bool in;
for(int i=6; i<=node; i++)
{
bool all = true;
in = false;
int nodecnt = 0, maxi = 0;
if( graph[i][1]<INF && graph[i][1]==graph[i][2] && graph[i][2]==graph[i][3]
&& graph[i][3]==graph[i][4] && graph[i][4]==graph[i][5])
{
nodecnt = nodecnt + 5;
mindis = min(mindis, graph[i][1]);
in = true;
}
if(in)
{
for(int j = 6; j<=node && in; j++)
{
if(graph[i][j]<INF)
{
maxi = max(maxi, graph[i][j]);
nodecnt++;
}
}
//cout<<"Node "<<i<<"= "<<maxi<<endl;
if(nodecnt==node)
{
if(in)cntdup++;
mini = min(mini, maxi);
}
}
}
if(cntdup==1) printf("Map %d: %d\n", cs, mindis);
else if(cntdup>1) printf("Map %d: %d\n", cs, mini);
else printf("Map %d: %d\n", cs, -1);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBJTkYgOTk5OTk5OTkKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgZ3JhcGhbMTA1XVsxMDVdOwoKdm9pZCBpbml0KCkKewogICAgZm9yKGludCBpPTE7IGk8PTEwMjsgaSsrKQogICAgewogICAgICAgIGZvcihpbnQgaj0xOyBqPD0xMDI7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKGk9PWopCiAgICAgICAgICAgICAgICBncmFwaFtpXVtqXSA9IDA7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIGdyYXBoW2ldW2pdID0gSU5GOwogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKQp7CiAgICBpbnQgdGVzdDsKICAgIHNjYW5mKCIlZCIsICZ0ZXN0KTsKICAgIGZvcihpbnQgY3MgPSAxOyBjczw9dGVzdDsgY3MrKykKICAgIHsKICAgICAgICBpbml0KCk7CiAgICAgICAgaW50IG5vZGUsIGVkZ2UsIHUsIHYsIGNvc3Q7CiAgICAgICAgc2NhbmYoIiVkICVkIiwgJm5vZGUsICZlZGdlKTsKICAgICAgICBmb3IoaW50IGk9MDsgaTxlZGdlOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBzY2FuZigiJWQgJWQgJWQiLCAmdSwgJnYsICZjb3N0KTsKICAgICAgICAgICAgZ3JhcGhbdV1bdl0gPSBncmFwaFt2XVt1XSA9IG1pbihjb3N0LCBncmFwaFt1XVt2XSk7CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaz0xOyBrPD1ub2RlOyBrKyspCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGk9MTsgaTw9bm9kZTsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IoaW50IGo9MTsgajw9bm9kZTsgaisrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGdyYXBoW2ldW2pdID0gbWluKGdyYXBoW2ldW2pdLCBncmFwaFtpXVtrXSArIGdyYXBoW2tdW2pdKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvKmZvcihpbnQgaT0xOyBpPD1ub2RlOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGo9MTsgajw9bm9kZTsgaisrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcmludGYoIiVkICIsIGdyYXBoW2ldW2pdKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBwcmludGYoIlxuIik7CiAgICAgICAgfSovCiAgICAgICAgaW50IGNudGR1cCA9IDAsIG1pbmRpcyA9IElORiwgbWluaSA9IElORjsKICAgICAgICBib29sIGluOwogICAgICAgIGZvcihpbnQgaT02OyBpPD1ub2RlOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBib29sIGFsbCA9IHRydWU7CiAgICAgICAgICAgIGluID0gZmFsc2U7CiAgICAgICAgICAgIGludCBub2RlY250ID0gMCwgbWF4aSA9IDA7CiAgICAgICAgICAgIGlmKCBncmFwaFtpXVsxXTxJTkYgJiYgZ3JhcGhbaV1bMV09PWdyYXBoW2ldWzJdICYmIGdyYXBoW2ldWzJdPT1ncmFwaFtpXVszXQogICAgICAgICAgICAgICAgJiYgZ3JhcGhbaV1bM109PWdyYXBoW2ldWzRdICYmIGdyYXBoW2ldWzRdPT1ncmFwaFtpXVs1XSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgbm9kZWNudCA9IG5vZGVjbnQgKyA1OwogICAgICAgICAgICAgICAgbWluZGlzID0gbWluKG1pbmRpcywgZ3JhcGhbaV1bMV0pOwogICAgICAgICAgICAgICAgaW4gPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGluKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IoaW50IGogPSA2OyBqPD1ub2RlICYmIGluOyBqKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaWYoZ3JhcGhbaV1bal08SU5GKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgbWF4aSA9IG1heChtYXhpLCBncmFwaFtpXVtqXSk7CiAgICAgICAgICAgICAgICAgICAgICAgIG5vZGVjbnQrKzsKICAgICAgICAg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