/*
 * ICPC Greater NY Regional, Nov 18 2018
 * Left-Right-Win solution by Fred Pickel, C-Scape Consulting Corp.
 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_N 15
#define	WEPS	0.01
#define LREPS 0.05
#define SUMEPS 0.08
#define SEPS .0001
#define SMALL_ONE
double c[MAX_N], d[MAX_N];

/*
 * NOTE: by synnetry Prob(n, 0, pleft, prt) = Prob(n, 0, prt, pleft)
 *		and for k > 0 Prob(n, k, pleft, prt) = Prob(n, n-k, prt, pleft)
 *
 *	If P[k] is the probability that player currently k steps clockwise around the table from the
 *  holder of the spinner wins:
 *  If 0 < k < n-1 :
 *		if the first spin is a win. k loses
 *		if the first spin is a move left. the player at k is now k-1 steps clockwise
 *			from the spinner so probability of left AND original k wins is Plft*P[k-1]
 *		if the first spin is a move right. the player at k is now k+1 steps clockwise
 *			from the spinner so probability of right AND original k wins is Prt*P[k+1]
 *	so P[k] = Plft*P[k-1] + Prt*P[k+1] OR
 *	P[k+1] = (1/Prt)*P[k] - (Plft/Prt)*P[k-1]
 *
 * if k == n-1, then k+1 = 0 so
 *		P[n-1] = Prt*P[0] + Plft*P[n-2]
 *	If k == 0,
 *		if the first spin is a win. 0 wins	with probability (1 - Plft - Prt)
 *		if the first spin is a move left. the player at 0 is now at position n-1
 *			with respect to the spinner so probability of left AND original 0 wins is Plft*P[n-1]
 *		if the first spin is a move right. the player at 0 is now at position 1
 *			with respect to the spinner so probability of right AND original 0 wins is Prt*P[1]
 *	so P[0] = (1 - Plft - Prt) + Prt*P[1] + Plft*P[n-1]
 *
 *	Finally, the sum of the ptobablities must be 1
 *	SUM(k = 0 .. (n-1)) P[k] = 1
 *
 *	We write P[k] = c[k]*P[0] + d[k]*P[1]
 *	c[0] = 1, d[0] = 0, c[1] = 0, d[1] = 1;
 *
 *	P[k+1] = c[k+1]*P[0] + d[k+1]*P[1] = (1/Prt)*P[k] - (Plft/Prt)*P[k-1] =
 *			= (1/Prt)*(c[k]*P[0] + d[k]*P[1]) - (Plft/Prt)*(c[k-1]*P[0] + d[k-1]*P[1])
 *			= ((1/Prt)*c[k] - (Plft/Prt)*c[k-1])*P[0] + ((1/Prt)*d[k] - (Plft/Prt)*d[k-1])*P[1]
 * so
 *		c[k+1] = (1/Prt)*c[k] - (Plft/Prt)*c[k-1]
 *		d[k+1] = (1/Prt)*d[k] - (Plft/Prt)*d[k-1]
 *
 * NOTE: c[k+1] and d{k+1] can look like (1/Prt)^k so if Prt is very small,
 *		c[k+1]  and d[k+1] can get very large
 *
 * from the k = 0 equation
 *		P[0] = (1 - Plft - Prt) + Plft*(c[n-1]*P[0] + d[n-1]*P[1]] + Prt*P[1]
 *	so
 *		(1 - Plft*c[n-1])*P[0] + (-Plft*d[n-1] - Prt)*P[1] = (1 - Plft - Prt)
 *
 * from the sum of all equation:
 *		SUM(k = 0 .. (n-1)) P[k] = SUM(k = 0 .. (n-1))(c[k]*P[0] + d[k]*P[1]) =
 *		(SUM(k = 0 .. (n-1))c[k])*P[0] + (SUM(k = 0 .. (n-1))d[k])*P[1] = 1
 *
 *	so now we have two equations in two unknowns
 *		a*P[0] + b*P[1] = x
 *		e*P[0] + f*P[1] = y
 *
 * NOTE: if Prt is very small, all of a, b, e, f can ve very large with small difference between
 *		so this algorithm can be numerically unstable for Prt very small
 *
 * solve for P[0] and P[1] then substitue to get
 *		P[k] = c[k]*P[0] + d[k]*P[1]
 *
 * To reduce potential numerical instability, use the synnetry equalities above to arrange that
 *	Prt is always the larger of the two probabilities
 */
double baseFindProb(int n, int k, double plft, double prt, int nprob)
{
	double csum, dsum, a, b, e, f, x, y;
	double ovrt, lftovrt, denom, p0, p1;
	int i;
	ovrt = 1.0/prt;
	lftovrt = ovrt*plft;
	c[0] = d[1] = csum = dsum = 1.0;
	c[1] = d[0] = 0.0;
	for(i = 2; i < n ; i++) {
		c[i] = ovrt*c[i-1] - lftovrt*c[i-2];
		d[i] = ovrt*d[i-1] - lftovrt*d[i-2];
		csum += c[i];
		dsum += d[i];
	}
	a = (1.0 - plft*c[n-1]); b = -plft*d[n-1] -prt; x = 1.0 - plft - prt;
	e = csum; f = dsum; y = 1.0;
	denom = a*f - b*e;
	if(fabs(denom) < SEPS) {
		fprintf(stderr, "denom %g too small problem %d\n", denom, nprob);
		return -1.0;
	}
	p0 = (x*f - b*y)/denom;
	p1 = (a*y - e*x)/denom;
	if((p0 < SEPS) || (p1 < SEPS) || ((1.0 - p0 - p1) < SEPS*(n-2))) {
		fprintf(stderr, "bad p0 %g p1 %g problem %d\n", p0, p1, nprob);
		return -1.0;
	}

	return (c[k]*p0 + d[k]*p1);
}

double findProb(int n, int k, double plft, double prt, int nprob)
{
	if(prt >= plft) {
		return baseFindProb(n, k, plft, prt, nprob);
	} else if (k == 0) {
		return baseFindProb(n, 0, prt, plft, nprob);
	} else {
		return baseFindProb(n, n-k, prt, plft, nprob);
	}
}

char inbuf[256];
int main()
{
	int nprob, curprob, index, n, k;
	double a, b, prob;
	if(fgets(&(inbuf[0]), 255, stdin) == NULL)
	{
		fprintf(stderr, "Read failed on problem count\n");
		return -1;
	}
	if(sscanf(&(inbuf[0]), "%d", &nprob) != 1)
	{
		fprintf(stderr, "Scan failed on problem count\n");
		return -2;
	}
	for(curprob = 1; curprob <= nprob ; curprob++)
	{
		if(fgets(&(inbuf[0]), 255, stdin) == NULL)
		{
			fprintf(stderr, "Read failed on problem %d header\n", curprob);
			return -3;
		}
		if(sscanf(&(inbuf[0]), "%d %d %d %lf %lf", &index, &n, &k, &a, &b) != 5) {
			fprintf(stderr, "scan failed on problem %d\n", curprob);
			return -4;
		}
		if(index != curprob)
		{
			fprintf(stderr, "problem index %d not = expected problem %d\n",
				index, curprob);
			return -5;
		}
		if((n < 2) || (n > MAX_N)) {
			fprintf(stderr, "number of players %d not in range 2 .. 15 problem %d\n", n, curprob);
			return -6;
		}
		if((k < 0) || (k >= n)){
			fprintf(stderr, "selected player %d not in range 0 .. n-1 problem %d\n", n, curprob);
			return -7;
		}
#ifdef SMALL_ONE
		if(((a + b) < SUMEPS) || ((1.0 - a - b) < WEPS)) {
			fprintf(stderr, "invalid probablities %.4lf %.4lf on problem %d\n", a, b, curprob);
			return -8;
		}
#else
		if((a < LREPS) || (b < LREPS) || ((1.0 - a - b) < WEPS)) {
			fprintf(stderr, "invalid probablities %.4lf %.4lf on problem %d\n", a, b, curprob);
			return -8;
		}
#endif
		prob = findProb(n, k, a, b, curprob);
		if(prob < 0.0) {
			fprintf(stderr, "invalid input on problem %d\n", curprob);
			return -9;
		} else {
			printf("%d %.2lf\n", curprob, 100.0*prob);
		}
	}
	return 0;
}
