#include <stdio.h>
#include <queue>
using namespace std;

#define MIN(a,b) (a<b?a:b)

typedef struct Node {
	double time;
	int node;
	bool operator<(Node const& that) const {
		return time > that.time;
	}
} Node;

typedef struct edge {
	int toPos;
	double time;
	double constart, conend;
} Edge;

double minTime[30];
vector<Edge> toEdges[30];

int m,n;

double getTimeXX(double startTime, double duration, double constart, double conend){
	if (duration>0){
		if (startTime<constart){
			double x = MIN(startTime+duration, constart);
			double d = x-startTime;
			return getTimeXX(x,duration-d, constart, conend)+d;
		} else if (startTime==constart){
			if (conend<=constart) return duration;

			double d = conend - startTime;

			if (d >= duration*2 ){
				return duration*2;
			} else {
				return d+getTimeXX(conend, duration-d/2, constart, conend);
			}
		} else if (startTime>conend){
			return duration;
		} else if (startTime>constart){
			return getTimeXX(startTime, duration, startTime, conend);
		}
	} else return 0;
}

int main(){

	while( scanf("%d%d", &n,&m)!=EOF ){
		if (n+m==0) break;

		for (int i=0;i<n;i++)
			toEdges[i].clear();


		for (int i=0;i<m;i++){
			Edge e;
			int p,q;
			char buff[100];

			scanf("%d%d%lf%s", &p,&q,&e.time,buff);

			double stime=-1, etime=-1;
			if (buff[0]=='R'){
				int ah,am,bh,bm;
				scanf("%d:%d%d:%d", &ah,&am,&bh,&bm);
				stime = ah*60+am;
				etime = bh*60+bm;
			} 
			e.constart = stime;
			e.conend = etime;

			e.toPos=p;
			toEdges[q].push_back(e);
			e.toPos=q;
			toEdges[p].push_back(e);
		}


		priority_queue<Node> pq;
		Node start;
		
		int a,b,sh,sm;
		scanf("%d%d%d:%d", &a,&b,&sh,&sm);
		start.node = a;
		start.time = sh*60+sm;

		for (int i=0;i<n;i++) minTime[i] = 1000000;

		pq.push(start);
		while (pq.size()){

			Node x = pq.top();
			pq.pop();

			if (x.time>minTime[b]) break;


			for (int i=0;i<toEdges[x.node].size();i++){
				Node next = x;
				double timexx = getTimeXX(x.time, toEdges[x.node][i].time, toEdges[x.node][i].constart, toEdges[x.node][i].conend);
				next.time += timexx;
				next.node = toEdges[x.node][i].toPos;
				if (next.time<minTime[next.node]){
					pq.push(next);
					minTime[next.node] = next.time;
				}
			}						
		}		

		printf("%.02lf\n", minTime[b]-start.time);
	}

	return 0;
}
