#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int WEEKTIME = 60*24*7;

int main() {
    int s, n, t, p, m;
    bool table[WEEKTIME];
    string weekday, time;
    cout.setf(ios::fixed);
    cout.precision(10);
    while (true) {
        cin >> s >> n >> t >> weekday >> time >> p >> m;
        if (s == 0) {
            break;
        }
        for (int i=0; i<WEEKTIME; i++) {
            table[i] = false;
        }
        for (int i=0; i<(weekday=="All"? 7: 1); i++) {
            if (time == "All" || time == "Day") {
                int stop = time=="All"? 24*60: 12*60;
                for (int j=0; j<stop; j++) {
                    table[i*60*24+j] = true;
                }
            }
            else {
                for (int j=0; j<6*60; j++) {
                    table[i*60*24+j] = true;
                    table[i*60*24+18*60+j] = true;
                }
            }
        }
        int hatched_stage_max = 0;
        for (int i=0; i<WEEKTIME; i++) {
            int hatched_stage = 0;
            int start = i;
            for (int j=0; j<m; j++) {
                if (table[start] && table[(start+s)%WEEKTIME]) {
                    hatched_stage++;
                }
                start = (start+t)%WEEKTIME;
            }
            hatched_stage_max = max(hatched_stage, hatched_stage_max);
        }
        cout << 1-pow(1-1.0/p, n*hatched_stage_max) << endl;
    }

    return 0;
}