#include <cstdio>
#include <iostream>
#include <map>
#include <cstring>

using namespace std;

int c[205][205];
map<string,int>a;

int main()
{
	int n,r,cnt = 1,t;
	char p[35],q[35];
	
	while (cin>>n>>r && (n+r))
	{
		memset(c, 0, sizeof(c));
		
		for (int i = 1; i <= r; i++)
		{
			cin>>p>>q>>t;
			
			if (!a.count(p))
				a[p] = cnt++;
			
			if (!a.count(q))
				a[q] = cnt++;
			
			c[a[p]][a[q]] = c[a[q]][a[p]] = t;
		}
		
		for (int k = 1; k <= n; k++)
		{
			for (int i = 1; i <= n; i++)
			{
				for (int j = 1; j <= n; j++)
				{
					c[i][j] = max(c[i][j],min(c[i][k],c[k][j]));
				}
			}
		}
		
		int n = 1;
		
		cin>>p>>q;
		cout<<"Scenario #"<<n++<<endl;
		cout<<c[a[p]][a[q]]<<" "<<"tons"<<endl;
		cout<<endl;
	}
	
	return 0;	
} 