#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <assert.h>
#include <map>
#include <queue>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sstream>
#include <math.h>
#include <bitset>
using namespace std;
typedef long long ll;
#define next dsifhsdkjf
#define REP(i,a,b) for(int i=(a);i<(b); ++i)
#define REPD(i,a,b)for(int i=(b)-1;i>=a;--i)
#define _(a,b) memset((a), (b), sizeof(a))
#define size(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define sqr(a) ((a)*(a))
double d[5001][10][10];
int main() {
#ifdef air
freopen("input.txt", "r", stdin);
freopen("output.txt","w", stdout);
#endif
int dx[4] = {+1, -1, 0, 0};
int dy[4] = {0, 0, +1, -1};
int test;
scanf("%d", &test);
REP(t, 0, test) {
int n, m, x1, y1, x2, y2, P;
cin >> n >> m >> x1 >> y1 >> x2 >> y2 >> P;
_(d, 0);
d[0][x1][y1]=1;
double res=0;
REP(it,0,P) REP(i,0,n) REP(j,0,m){
double c=d[it][i][j];
if (c < 1e-10) continue;
int cnt = 0;
if (i==x2 && y2==j) {
res += c;
continue;
}
REP(dir, 0, 4) {
int nx = i + dx[dir];
int ny = j + dy[dir];
if (nx < 0 || nx >= n || ny < 0 || ny >= m)
continue;
++cnt;
}
double pr = 1.0 / cnt;
REP(dir, 0, 4) {
int nx = i + dx[dir];
int ny = j + dy[dir];
if (nx < 0 || nx >= n || ny < 0 || ny >= m)
continue;
d[it+1][nx][ny] += pr*c;
++cnt;
}
}
res += d[P][x2][y2];
printf("%.10lf\n",res);
}
#ifdef air
printf("\n\n%.10lf\n", clock()*1e-3);
#endif
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWR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