#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

int s,n,t,p,m;
string w,ti;
int can[11000];
const int halfday = 720;
const int week = 10080;

int main(){
  while(cin >> s >> n >> t >> w >> ti >> p >> m,w!="None"){
    for(int i=0;i<week;i++)can[i] = false;

    int loop = (w == "All")?7:1;
    
    if(ti == "All"){
      for(int i=0;i<loop;i++){
	for(int j=0;j<2*halfday;j++)can[i*2*halfday+j] = true;
      }
    }else if(ti == "Day"){
      for(int i=0;i<loop;i++){
	for(int j=0;j<halfday;j++){
	  can[i*2*halfday + j + halfday/2] = true;
	}
      }
    }else{
      for(int i=0;i<loop;i++){
	for(int j=0;j<halfday/2;j++){
	  can[i*2*halfday + j] = true;
	  can[i*2*halfday + j + 3*halfday/2] = true;
	}
      }
    }

    int res = 0;
    int lim = (w=="All")?2*halfday:week;
    for(int start = 0;start < lim; start++){
      int now = start;
      int cnt = 0;
      for(int i=0;i<m;i++){
	if(can[now%week] && can[(now+s)%week])cnt++;
	now += t;
      }
      res = max(res,cnt);
    }
    printf("%.10lf\n",1-pow(1-1.0/p,n*res));
  }
}