//* Problem  : 1172 - Heavy Cargo
//* Contest  : acm.tju.edu.cn
//* Origin   : University of Ulm Local Contest 1999
//* Type     : Solution
//* Date     : 2008.06.06
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 8.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <iostream>
using namespace std;
#define int64 long long
#define INF 1000000000
#define EPS 1E-8

#define ALL(a) a.begin(), a.end()
#define PB(a, v) a.push_back(v)
#define MP(a,b) make_pair(a, b)
#define FOR(i, n) for (int i = 0; i < (n); i++)

int index(vector <string> &ss, string s)
{
	for (int i = 0; i < ss.size(); i++)
		if (ss[i] == s) return i;
	PB(ss, s);
	return ss.size() - 1;
}

int a[256][256];

int main()
{
#ifdef _DEBUG
	freopen("1166.in", "r", stdin);
#endif
	int n, m, it = 0;
	while (scanf("%d%d", &n, &m) == 2 && n)
	{
		printf("Scenario #%d\n", ++it);
		vector <string> ss; string s; int k1, k2, w, res = 0;
		memset(a, 0, sizeof(a));
		for (int i = 0; i < m; i++)
		{ 
			cin >> s; k1 = index(ss, s); cin >> s; k2 = index(ss, s); scanf("%d", &w);
			a[k1][k2] = a[k2][k1] = w;
		}
		cin >> s; k1 = index(ss, s); cin >> s; k2 = index(ss, s);
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					a[i][j] = max(a[i][j], min(a[i][k], a[k][j]));
		res = a[k1][k2];
		printf("%d tons\n", res);
		printf("\n");
	}
	return 0;
}
