// Arup Guha
// 4/11/2023
// Solution to 2017 MAPS Problem D: Genius

using namespace std;
#include <bits/stdc++.h>

void fillProb(int* w, double* p) ;

int main() {

    // Get basic input.
    int k, t, p, q, x1;
    cin >> k >> t >> p >> q >> x1;
    vector<int> pred;
    pred.push_back(x1);

    // Calculate list.
    for (int i=2; i<=t; i++) {
        int nxt = (pred[i-2]*p)%q;
        pred.push_back(nxt);
    }

    for (int i=0; i<pred.size(); i++)
        pred[i] = pred[i]%4;

    // Read weights.
    int weights[100][4];
    for (int i=0; i<t; i++)
        for (int j=0; j<4; j++)
            cin >> weights[i][j];

    // dp[i][j] = correct pred in j out of i games.
    double dp[t+1][t+1];
    for (int i=0; i<=t; i++)
        for (int j=0; j<=t; j++)
            dp[i][j] = 0;

    // Always win 0 out of 0.
    dp[0][0] = 1;

    // Loop over games.
    for (int i=1; i<=t; i++) {

        // Get relevant probabilities.
        double prob[4];
        fillProb(weights[i-1], prob);

        // Probabilities this is predicted correctly.
        double wG = prob[pred[i-1]];
        double lG = 1-wG;

        // Lose this game...
        dp[i][0] = dp[i-1][0]*lG;

        // These states can come from winning or losing last game.
        for (int j=1; j<=i; j++)
            dp[i][j] = dp[i-1][j-1]*wG + dp[i-1][j]*lG;
    }

    // Add and print.
    double res = 0;
    for (int i=k; i<=t; i++) res += dp[t][i];
    printf("%.9f\n", res);
    return 0;
}

// Hard codes probability of each of 4 teams winning.
void fillProb(int* w, double* p) {

    // Just calculate each pairwise probability.
    double win[4][4];
    for (int i=0; i<4; i++)
        for (int j=0; j<4; j++)
            win[i][j] = 1.0*w[i]/(w[i]+w[j]);

    // Hard-coded probability tree =)
    p[0] = win[0][1]*(win[2][3]*win[0][2]+win[3][2]*win[0][3]);
    p[1] = win[1][0]*(win[2][3]*win[1][2]+win[3][2]*win[1][3]);
    p[2] = win[2][3]*(win[0][1]*win[2][0]+win[1][0]*win[2][1]);
    p[3] = win[3][2]*(win[0][1]*win[3][0]+win[1][0]*win[3][1]);
}
