#include #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; typedef unsigned long long ull; typedef pair pii; typedef long long ll; template inline void read(T &f) { f = 0; T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } f *= fu; } template void print(T x) { if (x < 0) putchar('-'), x = -x; if (x < 10) putchar(x + 48); else print(x / 10), putchar(x % 10 + 48); } template void print(T x, char t) { print(x); putchar(t); } const int N = 260; long double a[N][N], ans[N]; void gauss() { for (int i = 0; i < 256; i++) { int pos = i; for (int j = i; j < 256; j++) { if (fabs(a[j][i]) > fabs(a[pos][i])) { pos = j; } } swap(a[pos], a[i]); for (int j = i + 1; j < 256; j++) { long double coef = a[j][i] / a[i][i]; for (int k = i; k <= 256; k++) a[j][k] -= coef * a[i][k]; } } for (int i = 255; i >= 0; i--) { ans[i] = a[i][256]; for (int j = i + 1; j < 256; j++) ans[i] += ans[j] * a[i][j]; ans[i] /= -a[i][i]; } } int T; int main() { for (int i = 0; i < 256; i++) { static int seq[8]; for (int j = 0; j < 8; j++) seq[j] = (i >> j) & 1; int len = 0, sum = 0; while (1) { int cando = 0; // for (int j = 0; j < 8 - len; j++) cout << seq[j]; // cout << endl; for (int l = 0, r; l < 8 - len; l = r + 1) { r = l; while (r + 1 < 8 - len && seq[l] == seq[r + 1]) ++r; if (r - l + 1 >= 3) { for (int j = r + 1; j < 8 - len; j++) seq[j - (r - l + 1)] = seq[j]; len += r - l + 1; sum += (r - l + 1) * (r - l + 1); cando = 1; break; } } if (!cando) break; } // fprintf(stderr, "len = %d\n", len); a[i][i] = -1; if (len) { a[i][256] += sum; long double inv = (long double)1 / (1 << len); for (int j = 0; j < (1 << len); j++) { for (int k = 0; k < len; k++) seq[7 - k] = (j >> k) & 1; int go = 0; for (int k = 0; k < 8; k++) go |= (seq[k] << k); a[i][go] += inv; } } } gauss(); read(T); while (T--) { static char c[10]; scanf("%s", c); int now = 0; for (int i = 0; i < 8; i++) now |= (c[i] - '0') << i; printf("%.7lf\n", (double)ans[now]); } return 0; }