#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <cassert>
using namespace std;
typedef pair<int, int> PII;
const int ALLDAY = 24 * 60;
const string WD[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
double calc(int a, int n, int p){
  double pp = 1.0 - (1.0 / (double)p);
  return 1.0 - pow(pp, a*n);
}
PII get_next(int cur_min, int weekday, int step){
  int nmin = cur_min + step;
  if(nmin >= ALLDAY){
    return make_pair(nmin % ALLDAY, (weekday+1) % 7);
  }
  return make_pair(nmin, weekday);
}
int main(){
  int s, n, t, p, m;
  string weekday, time;
  while(true){
    cin >> s >> n >> t >> weekday >> time >> p >> m;
    if((s|n|t|p|m) == 0 && weekday == "None" && time == "None"){
      break;
    }
    bool flag_time[ALLDAY], flag_wd[7];
    if(time == "All"){
      fill_n(flag_time, ALLDAY, true);
    }
    else if(time == "Day"){
      fill_n(flag_time, ALLDAY, false);
      fill_n(flag_time+6*60, ALLDAY/2, true);
    }else{
      fill_n(flag_time, ALLDAY, true);
      fill_n(flag_time+6*60, ALLDAY/2, false);
    }
    if(weekday == "All"){
      fill_n(flag_wd, 7, true);
    }
    else{
      fill_n(flag_wd, 7, false);
      for(int i = 0; i < 7; ++i){
	if(weekday == WD[i]){
	  flag_wd[i] = true;
	  break;
	}
      }
    }
    int max_a = 0;
    for(int s_min = 0; s_min < ALLDAY; ++s_min){
      for(int s_wd = 0; s_wd < 7; ++s_wd){
	int a = 0;
	int c_min = s_min, c_wd = s_wd;
	for(int g = 0; g < m; ++g){
	  assert(c_min!=ALLDAY); //
	  assert(c_wd<7); //
	  PII huka = get_next(c_min, c_wd, s);
	  if(flag_time[huka.first] && flag_time[c_min] && flag_wd[c_wd] && flag_wd[huka.second]){
	    ++a;
	  }
	  PII next = get_next(c_min, c_wd, t);
	  c_min = next.first;
	  c_wd = next.second;
	}
	max_a = max(max_a, a);
      } 
    }
    //cout << max_a << endl;
    printf("%0.11f\n", calc(n, max_a, p));
  }
  return 0;
}