import math

def P2R(p):
    sine = math.sin(p[0])
    return (sine*math.cos(p[1]),sine*math.sin(p[1]),math.cos(p[0]))

def dist(p1, p2):
    x = p1[0] - p2[0]
    y = p1[1] - p2[1]
    z = p1[2] - p2[2]
    return math.sqrt(x*x + y*y + z*z)

def elim_spaces(s):
    result = ""
    for char in s:
        if char != ' ':
            result += char
    return result

def parse_point(s):
    s = s.split(",")
    return (math.pi*float(s[0]),math.pi*float(s[1]))

for _ in range(int(input())):
    p1,p2 = (elim_spaces(input())[1:-1]).split(")(")
    print("%.3f"%dist(P2R(parse_point(p1)), P2R(parse_point(p2))))
