#include #include using namespace std; #if __cplusplus > 201703L #include using namespace numbers; #endif // T must support +=, -=, *, *=, ==, and != template struct matrix{ using ring_t = T; using domain_t = vector; using range_t = vector; int n, m; vector> data; vector &operator()(int i){ assert(0 <= i && i < n); return data[i]; } const vector &operator()(int i) const{ assert(0 <= i && i < n); return data[i]; } T &operator()(int i, int j){ assert(0 <= i && i < n && 0 <= j && j < m); return data[i][j]; } const T &operator()(int i, int j) const{ assert(0 <= i && i < n && 0 <= j && j < m); return data[i][j]; } operator vector>() const{ return data; } bool operator==(const matrix &a) const{ assert(n == a.n && m == a.m); return data == a.data; } bool operator!=(const matrix &a) const{ assert(n == a.n && m == a.m); return data != a.data; } matrix &operator+=(const matrix &a){ assert(n == a.n && m == a.m); for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) data[i][j] += a(i, j); return *this; } matrix operator+(const matrix &a) const{ return matrix(*this) += a; } matrix &operator-=(const matrix &a){ assert(n == a.n && m == a.m); for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) data[i][j] -= a(i, j); return *this; } matrix operator-(const matrix &a) const{ return matrix(*this) -= a; } matrix operator*=(const matrix &a){ assert(m == a.n); int l = a.m; matrix res(n, l); for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) for(auto k = 0; k < l; ++ k) res(i, k) += data[i][j] * a(j, k); return *this = res; } matrix operator*(const matrix &a) const{ return matrix(*this) *= a; } matrix &operator*=(T c){ for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) data[i][j] *= c; return *this; } matrix operator*(T c) const{ return matrix(*this) *= c; } template::value>::type* = nullptr> matrix &inplace_power(U e){ assert(n == m && e >= 0); matrix res(n, n, T(1)); for(; e; *this *= *this, e >>= 1) if(e & 1) res *= *this; return *this = res; } template matrix power(U e) const{ return matrix(*this).inplace_power(e); } matrix &inplace_transpose(){ assert(n == m); for(auto i = 0; i < n; ++ i) for(auto j = i + 1; j < n; ++ j) swap(data[i][j], data[j][i]); return *this; } matrix transpose() const{ if(n == m) return matrix(*this).inplace_transpose(); matrix res(m, n); for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) res(j, i) = data[i][j]; return res; } range_t operator*(const domain_t &v) const{ assert(m == (int)v.size()); vector res(n, T(0)); for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) res[i] += data[i][j] * v[j]; return res; } // Assumes T is either a floating, integral, or a modular type. // If T is a floating type, O(n) divisions with O(n^3) additions, subtractions, and multiplications. // Otherwise, O(n^2 * log(size)) divisions with O(n^3) additions, subtractions, and multiplications. // Returns {REF matrix, determinant, rank} tuple inplace_REF(){ if(n == 0) return {*this, T(1), 0}; T det = 1; int rank = 0; for(auto j = 0; j < m; ++ j){ if constexpr(is_floating_point_v){ static const T eps = 1e-9; int pivot = rank; for(auto i = rank + 1; i < n; ++ i) if(abs(data[pivot][j]) < abs(data[i][j])) pivot = i; if(rank != pivot){ swap(data[rank], data[pivot]); det *= -1; } if(abs(data[rank][j]) <= eps) continue; det *= data[rank][j]; T inv = 1 / data[rank][j]; for(auto i = rank + 1; i < n; ++ i) if(abs(data[i][j]) > eps){ T coef = data[i][j] * inv; for(auto k = j; k < m; ++ k) data[i][k] -= coef * data[rank][k]; } ++ rank; } else{ for(auto i = rank + 1; i < n; ++ i) while(data[i][j]){ T q; if constexpr(is_integral_v || is_same_v || is_same_v) q = data[rank][j] / data[i][j]; else q = data[rank][j].data / data[i][j].data; if(q) for(auto k = j; k < m; ++ k) data[rank][k] -= q * data[i][k]; swap(data[rank], data[i]); det *= -1; } if(rank == j) det *= data[rank][j]; else det = T(0); if(data[rank][j]) ++ rank; } if(rank == n) break; } return {*this, det, rank}; } // Assumes T is either a floating, integral, or a modular type. // If T is a floating type, O(n) divisions with O(n^3) additions, subtractions, and multiplications. // Otherwise, O(n^2 * log(size)) divisions with O(n^3) additions, subtractions, and multiplications. // Returns {REF matrix, determinant, rank} tuple REF() const{ return matrix(*this).inplace_REF(); } // Assumes T is a field. // O(n) divisions with O(n^3) additions, subtractions, and multiplications. // Returns {REF matrix, determinant, rank} tuple inplace_REF_field(){ if(n == 0) return {*this, T(1), 0}; T det = T(1); int rank = 0; for(auto j = 0; j < m; ++ j){ int pivot = -1; for(auto i = rank; i < n; ++ i) if(data[i][j] != T(0)){ pivot = i; break; } if(!~pivot){ det = T(0); continue; } if(rank != pivot){ swap(data[rank], data[pivot]); det *= -1; } det *= data[rank][j]; T inv = 1 / data[rank][j]; for(auto i = rank + 1; i < n; ++ i) if(data[i][j] != T(0)){ T coef = data[i][j] * inv; for(auto k = j; k < m; ++ k) data[i][k] -= coef * data[j][k]; } ++ rank; if(rank == n) break; } return {*this, det, rank}; } // Assumes T is a field. // O(n) divisions with O(n^3) additions, subtractions, and multiplications. // Returns {REF matrix, determinant, rank} tuple REF_field() const{ return matrix(*this).inplace_REF_field(); } // Assumes T is a field. // O(n) divisions with O(n^3) additions, subtractions, and multiplications. optional inverse() const{ assert(n == m); if(n == 0) return *this; auto a = data; vector> res(n, vector(n, T(0))); for(auto i = 0; i < n; ++ i) res[i][i] = T(1); for(auto j = 0; j < n; ++ j){ int rank = j, pivot = -1; for(auto i = rank; i < n; ++ i) if(a[i][j] != T(0)){ pivot = i; break; } if(!~pivot) return {}; swap(a[rank], a[pivot]), swap(res[rank], res[pivot]); T inv = 1 / a[rank][j]; for(auto k = j; k < n; ++ k) a[rank][k] *= inv, res[rank][k] *= inv; for(auto i = 0; i < n; ++ i) if(i != j && a[i][j] != T(0)){ T d = a[i][j]; for(auto k = j; k < n; ++ k) a[i][k] -= d * a[j][k], res[i][k] -= d * res[j][k]; } } return res; } // Assumes T is either a floating, integral, or a modular type. // If T is a floating type, O(n) divisions with O(n^3) additions, subtractions, and multiplications. // Otherwise, O(n^2 * log(size)) divisions with O(n^3) additions, subtractions, and multiplications. T determinant() const{ assert(n == m); return get<1>(REF()); } // Assumes T is a field. // O(n) divisions with O(n^3) additions, subtractions, and multiplications. T determinant_field() const{ assert(n == m); return get<1>(REF_field()); } // Assumes T is either a floating, integral, or a modular type. // If T is a floating type, O(n) divisions with O(n^3) additions, subtractions, and multiplications. // Otherwise, O(n^2 * log(size)) divisions with O(n^3) additions, subtractions, and multiplications. int rank() const{ return get<2>(REF()); } // Assumes T is a field. // O(n) divisions with O(n^3) additions, subtractions, and multiplications. int rank_field() const{ return get<2>(REF_field()); } // O(n * 2^n) T permanent() const{ assert(n <= 30 && n == m); T perm = n ? 0 : 1; vector sum(n); for(auto order = 1; order < 1 << n; ++ order){ int j = __lg(order ^ order >> 1 ^ order - 1 ^ order - 1 >> 1), sign = (order ^ order >> 1) & 1 << j ? 1 : -1; T prod = order & 1 ? -1 : 1; if((order ^ order >> 1) & 1 << j) for(auto i = 0; i < n; ++ i) prod *= sum[i] += data[i][j]; else for(auto i = 0; i < n; ++ i) prod *= sum[i] -= data[i][j]; perm += prod; } return perm * (n & 1 ? -1 : 1); } template friend output_stream &operator<<(output_stream &out, const matrix &a){ out << "\n"; for(auto i = 0; i < a.n; ++ i){ for(auto j = 0; j < a.m; ++ j){ out << a(i, j) << " "; } out << "\n"; } return out; } matrix(int n, int m, T init_diagonal = T(0), T init_off_diagonal = T(0)): n(n), m(m){ data.assign(n, vector(m, T(0))); for(auto i = 0; i < n; ++ i) for(auto j = 0; j < m; ++ j) data[i][j] = i == j ? init_diagonal : init_off_diagonal; } matrix(const vector> &arr, int _n = -1, int _m = -1): n(~_n ? _n : (int)arr.size()), m(~_m ? _m : (int)arr[0].size()), data(arr){ } static matrix additive_identity(int n, int m){ return matrix(n, m, T(0), T(0)); } static matrix multiplicative_identity(int n, int m){ return matrix(n, m, T(1), T(0)); } }; template matrix operator*(T c, matrix a){ for(auto i = 0; i < a.n; ++ i) for(auto j = 0; j < a.m; ++ j) a(i, j) = c * a(i, j); return a; } // Multiply a row vector v on the left template typename matrix::domain_t operator*(const typename matrix::range_t &v, const matrix &a){ assert(a.n == (int)size(v)); typename matrix::domain_t res(a.m, T(0)); for(auto i = 0; i < a.n; ++ i) for(auto j = 0; j < a.m; ++ j) res[j] += v[i] * a(i, j); return res; } int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); cout << fixed << setprecision(5); auto __solve_tc = [&](auto __tc_num)->int{ array, 2> a; for(auto i = 0; i < 2; ++ i){ for(auto j = 0; j < 2; ++ j){ cin >> a[i][j]; } } double det = max(0.0, (a[0][0] - a[1][1]) * (a[0][0] - a[1][1]) + 4 * a[0][1] * a[1][0]); if(det <= 1e-11){ for(auto i = 0; i < 2; ++ i){ for(auto j = 0; j < 2; ++ j){ cout << cbrt(a[i][j]) << " \n"[j]; } } } else{ double alpha = ((a[0][0] + a[1][1]) + sqrt(det)) / 2; double beta = ((a[0][0] + a[1][1]) - sqrt(det)) / 2; matrix basis(2, 2), mat(2, 2); basis(0, 0) = a[0][1] + a[1][1] - alpha, basis(0, 1) = a[0][1] + a[1][1] - beta; basis(1, 0) = alpha - a[0][0] - a[1][0], basis(1, 1) = beta - a[0][0] - a[1][0]; mat(0, 0) = cbrt(alpha), mat(1, 1) = cbrt(beta); mat = basis * mat * *basis.inverse(); for(auto i = 0; i < 2; ++ i){ for(auto j = 0; j < 2; ++ j){ cout << mat(i, j) << " \n"[j]; } } } return 0; }; int __tc_cnt; cin >> __tc_cnt; for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){ __solve_tc(__tc_num); } return 0; } /* */ //////////////////////////////////////////////////////////////////////////////////////// // // // Coded by Aeren // // // ////////////////////////////////////////////////////////////////////////////////////////