import sys
import math
input = sys.stdin.readline
T = int(input())
for _ in range(T):
a, b = map(int, input().split())
if a==1:
x,y,z = map(float, input().split())
if b==2:
# cartesian -> cylinder
r = math.sqrt(x*x+y*y)
if r < 1e-6:
t = 0
else:
t = math.acos(x/r)
print(r,t,z)
if b==3:
# cartesian -> spherical
r = math.sqrt(x*x+y*y+z*z)
if r < 1e-6:
u = 0
t = 0
else:
u = math.asin(abs(z)/r)
t = math.acos(x/r)
print(r,u,t)
if a==2:
r,t,z = map(float, input().split())
if b==1:
# cylinder -> cartesian
x = r*math.cos(t)
y = r*math.sin(t)
print(x,y,z)
if b==3:
# cylinder -> spherical
r_ = math.sqrt(r*r+z*z)
if r_ < 1e-6:
u = 0
else:
u = math.acos(abs(z)/r_)
print(r_, u, t)
if a==3:
r,u,t = map(float, input().split())
if r < 1e-6:
print(0,0,0)
continue
if b==1:
# spherical -> cartesian
r_ = r*math.sin(u)
x = r_*math.cos(t)
y = r_*math.sin(t)
z = r*math.cos(u)
print(x, y, z)
if b==2:
# spherical -> cylinder
r_ = r*math.sin(u)
z = r*math.cos(u)
print(r_,t,z)
aW1wb3J0IHN5cwppbXBvcnQgbWF0aAoKaW5wdXQgPSBzeXMuc3RkaW4ucmVhZGxpbmUKClQgPSBpbnQoaW5wdXQoKSkKCmZvciBfIGluIHJhbmdlKFQpOgogICAgYSwgYiA9IG1hcChpbnQsIGlucHV0KCkuc3BsaXQoKSkKICAgIAogICAgaWYgYT09MToKICAgICAgICB4LHkseiA9IG1hcChmbG9hdCwgaW5wdXQoKS5zcGxpdCgpKQogICAgICAgIAogICAgICAgIGlmIGI9PTI6CiAgICAgICAgICAgICMgY2FydGVzaWFuIC0+IGN5bGluZGVyCiAgICAgICAgICAgIHIgPSBtYXRoLnNxcnQoeCp4K3kqeSkKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmIHIgPCAxZS02OgogICAgICAgICAgICAJdCA9IDAKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgCXQgPSBtYXRoLmFjb3MoeC9yKQogICAgICAgICAgICAJCiAgICAgICAgICAgIHByaW50KHIsdCx6KQogICAgICAgICAgICAKICAgICAgICBpZiBiPT0zOgogICAgICAgICAgICAjIGNhcnRlc2lhbiAtPiBzcGhlcmljYWwKICAgICAgICAgICAgciA9IG1hdGguc3FydCh4KngreSp5K3oqeikKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmIHIgPCAxZS02OgogICAgICAgICAgICAJdSA9IDAKICAgICAgICAgICAgCXQgPSAwCiAgICAgICAgICAgIGVsc2U6CgkgICAgICAgICAgICB1ID0gbWF0aC5hc2luKGFicyh6KS9yKQoJICAgICAgICAgICAgdCA9IG1hdGguYWNvcyh4L3IpCiAgICAgICAgICAgIHByaW50KHIsdSx0KQogICAgICAgIAogICAgaWYgYT09MjoKICAgICAgICByLHQseiA9IG1hcChmbG9hdCwgaW5wdXQoKS5zcGxpdCgpKQogICAgICAgIAogICAgICAgIGlmIGI9PTE6CiAgICAgICAgICAgICMgY3lsaW5kZXIgLT4gY2FydGVzaWFuCiAgICAgICAgICAgIHggPSByKm1hdGguY29zKHQpCiAgICAgICAgICAgIHkgPSByKm1hdGguc2luKHQpCiAgICAgICAgICAgIHByaW50KHgseSx6KQogICAgICAgIAogICAgICAgIGlmIGI9PTM6CiAgICAgICAgICAgICMgY3lsaW5kZXIgLT4gc3BoZXJpY2FsCiAgICAgICAgICAgIHJfID0gbWF0aC5zcXJ0KHIqcit6KnopCiAgICAgICAgICAgIGlmIHJfIDwgMWUtNjoKICAgICAgICAgICAgCXUgPSAwCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgIAl1ID0gbWF0aC5hY29zKGFicyh6KS9yXykKICAgICAgICAgICAgcHJpbnQocl8sIHUsIHQpCiAgICAgICAgCiAgICBpZiBhPT0zOgogICAgICAgIHIsdSx0ID0gbWFwKGZsb2F0LCBpbnB1dCgpLnNwbGl0KCkpCiAgICAgICAgCiAgICAgICAgaWYgciA8IDFlLTY6CiAgICAgICAgCXByaW50KDAsMCwwKQogICAgICAgIAljb250aW51ZQogICAgICAgICAgICAKICAgICAgICBpZiBiPT0xOgogICAgICAgICAgICAjIHNwaGVyaWNhbCAtPiBjYXJ0ZXNpYW4KICAgICAgICAgICAgcl8gPSByKm1hdGguc2luKHUpCiAgICAgICAgICAgIHggPSByXyptYXRoLmNvcyh0KQogICAgICAgICAgICB5ID0gcl8qbWF0aC5zaW4odCkKICAgICAgICAgICAgeiA9IHIqbWF0aC5jb3ModSkKICAgICAgICAgICAgcHJpbnQoeCwgeSwgeikKICAgICAgICAgICAgCiAgICAgICAgaWYgYj09MjoKICAgICAgICAgICAgIyBzcGhlcmljYWwgLT4gY3lsaW5kZXIKICAgICAgICAgICAgcl8gPSByKm1hdGguc2luKHUpCiAgICAgICAgICAgIHogPSByKm1hdGguY29zKHUpCiAgICAgICAgICAgIHByaW50KHJfLHQseikKICAgICAgICA=
NgoxIDIKMC4wMDAwMDAwMCAwLjAwMDAwMDAwIDAuMDAwMDAwMDAKMSAzCjAuMDAwMDAwMDAgMC4wMDAwMDAwMCAwLjAwMDAwMDAwCjIgMQowLjAwMDAwMDAwIDAuMDAwMDAwMDAgMC4wMDAwMDAwMAoyIDMKMC4wMDAwMDAwMCAwLjAwMDAwMDAwIDAuMDAwMDAwMDAKMyAxCjAuMDAwMDAwMDAgMC4wMDAwMDAwMCAwLjAwMDAwMDAwCjMgMgowLjAwMDAwMDAwIDAuMDAwMDAwMDAgMC4wMDAwMDAwMA==
6
1 2
0.00000000 0.00000000 0.00000000
1 3
0.00000000 0.00000000 0.00000000
2 1
0.00000000 0.00000000 0.00000000
2 3
0.00000000 0.00000000 0.00000000
3 1
0.00000000 0.00000000 0.00000000
3 2
0.00000000 0.00000000 0.00000000