#include <iostream> #include <iomanip> #include <algorithm> using namespace std; typedef pair<double, double> P; int k; double p; double expDays[1001]; pair<double, double> eq[1001]; double calcDays() { eq[k] = P(0, 0); for( int i = k - 1; i >= 0; i -- ) { eq[i] = P( (1 - p) + p * eq[i + 1].first, p * eq[i + 1].second + 1 ); } expDays[0] = eq[0].second / (1. - eq[0].first); for( int i = 1; i <= k; i ++ ) expDays[i] = expDays[0] * eq[i].first + eq[i].second; return expDays[0]; } double calcMoney() { eq[k] = P(0, 0); for( int i = k - 1; i >= 0; i -- ) eq[i] = P( (1 - p) + p * eq[i + 1].first, p * eq[i + 1].second + 2 * expDays[i] ); double result = eq[0].second / (1. - eq[0].first) - expDays[0]; return result; } int t; int main() { //~ freopen("kconsecutive.in", "r", stdin); //~ freopen("kconsecutive.out", "w", stdout); for( cin >> t; t--; ) { cin >> p >> k; double days = calcDays(); double money = calcMoney(); cout.precision( 3 ); cout.setf( ios::fixed | ios::showpoint ); cout << days << " " << money << endl; } return 0; }