#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int s,n,t,p,m;
string w,T;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>s>>n>>t>>w>>T>>p>>m && s){
		int ok,cycle;
		if(w=="All"){
			if(T=="All")ok=1,cycle=1;
			else ok=720,cycle=1440;
		}else{
			if(T=="All")ok=1440,cycle=10080;
			else if(T=="Day")ok=720,cycle=10080;
			else ok=-1,cycle=10080;
		}
		int maxchance=0;
		if(ok==1 && cycle==1){
			maxchance=m;
		}
		else rep(i,cycle){
			int cur=i,chance=0;
			rep(j,m){
				int hatch=cur+s;
				if(ok!=-1){
					if(hatch<ok)chance++;
				}else{
					if(hatch<360 || 1080<=cur && hatch<1440)chance++;
				}
				cur=(cur+t)%cycle;
			}
			maxchance=max(maxchance,chance);
		}
		cout<<fixed<<setprecision(16)<<1-pow(1-1./p,maxchance*n)<<endl;
	}
}