#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <queue>
#include <ctime>
using namespace std;
template <class T> void checkmin(T &t,T x){if (x < t) t = x;}
template <class T> void checkmax(T &t,T x){if (x > t) t = x;}
template <class T> void _checkmin(T &t, T x){if (t == -1) t = x; if (x < t) t = x;}
template <class T> void _checkmax(T &t, T x){if (t == -1) t = x; if (x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <long double,long double> PDD;
typedef long long lld;
#define foreach(it,v) for (__typeof((v).begin()) it = (v).begin();it != (v).end();it++)
#define DEBUG(a) cout << #a" = " << (a) << endl;
#define DEBUGARR(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }
#define maxn 2200
#define maxm 10000
long double f[maxn][60];
int edge[maxn],next[maxm],node[maxm],No[maxm],tot,T;
void insert(int a,int b,int i){
    node[tot] = b,next[tot] = edge[a],No[tot] = i,edge[a] = tot++;
}
map<string,int> Name;
int checkin(char s[]){
    if (Name[s]==0) Name[s] = ++T;
    return Name[s];
}
int L,R,Q[maxm*200],mark[maxn];
void push(int i){
    if (!mark[i]){
        mark[i] = 1;
        Q[R++] = i;
    }
}
void dfs(int now){
    mark[now] = 1;
    for (int i=edge[now];i!=-1;i=next[i])
        if (!mark[node[i]])
            dfs(node[i]);
}
int dep[maxn],st[maxn],D[maxn],from[maxm],to[maxm];
long double P[maxn];
int main(){
#ifdef cwj
    freopen("in", "r", stdin);
#endif
    int tt;
    int i,j,N,src,dest,d,k;
    char as[100],bs[100],srcs[100],dests[100];
    scanf("%d",&tt);
    while(tt--){
        memset(edge,-1,sizeof(edge));
        tot = 0;
        T = 0;
        Name.clear();
        scanf("%s%s",srcs,dests);
        src = checkin(srcs);
        dest = checkin(dests);
        scanf("%d",&N);
        for (i=0;i<N;i++){
            scanf("%s%s%d%d%Lf%d",as,bs,&dep[i],&st[i],&P[i],&D[i]);
            from[i] = checkin(as);
            to[i] = checkin(bs);
            insert(to[i],from[i],i);
            P[i]/=100;
        //  Rinsert(to[i],from[i]);
        }
        for (i=1;i<=T;i++)
            mark[i] = 0;
        dfs(dest);
        if (mark[src]==0){
            printf("IMPOSSIBLE\n");
            continue;
        }
        long double oo = 1e15;
        for (i=1;i<=T;mark[i++] =0)
            for (j=0;j<60;j++)
                f[i][j] = oo;
        for (i=0;i<N;mark[i++] = 0);
    
        for (i=0;i<60;i++)
            f[dest][i] = 0;
        L = 0,R = 0;
        for (i=edge[dest];i!=-1;i=next[i])
            push(No[i]);
        int minj;
        while(L<R){
            int nowe = Q[L++],now = to[nowe],pre = from[nowe];
            mark[nowe] = false;
            bool upd = 0;
            minj = -1;
            for (j=0;j<60;j++)
            if (j==dep[nowe]){
                long double tmp = 0;
                tmp = (f[now][((j+st[nowe])%60+60)%60]+st[nowe])*(1-P[nowe]);
                for (d=1;d<=D[nowe];d++){
                    k = ((j+st[nowe]+d)%60+60)%60;
                    tmp+=(f[now][k]+st[nowe]+d)*P[nowe]/D[nowe];
                }

                if (tmp<f[pre][j]){
                    upd = 1;
                    f[pre][j] = tmp;
                }
                minj = j;
            }

            if (upd){
            		for (j=0;j<60;minj = (minj-1+60)%60,j++)
            	          checkmin(f[pre][(minj-1+60)%60],f[pre][minj]+1);
                for (j=edge[pre];j!=-1;j=next[j])
                    push(No[j]);
            }
        }
     /*   for(i=1;i<=N;i++)
        	for (j=0;j<60;j++)
        		printf("%d %d :%Lf\n",i,j,f[i][j]);*/
        minj = -1;
        for (j=0;j<60;j++)
            if (f[src][j]!=oo){
            		//printf("%d %d %Lf\n",src,j,f[src][j]);
                if (minj==-1||f[src][minj]>f[src][j])
                    minj = j;
            }
        if (minj==-1) printf("IMPOSSIBLE\n");
        else printf("%.9Lf\n",f[src][minj]);

    }
}
