# Arup Guha
# 4/19/2025
# Solution? to Kattis Problem: Cranes
# https://open.kattis.com/problems/cranes

# Returns the subset of items designated by mask.
def getBits(mask):

    res = []
    i = 0

    # Go through each possible bit.
    while (1<<i) <= mask:

        # If it's on, add it.
        if (mask & (1<<i)) != 0:
            res.append(i)

        # Go to next.
        i += 1

    # Here is the subset.
    return res

# Returns true if cranes c1 and c2 intersect.
def intersect(c1, c2):

    # Get distnace squared between two centers.
    dsq = (c1[0]-c2[0])*(c1[0]-c2[0]) + (c1[1]-c2[1])*(c1[1]-c2[1])

    # Get square of sum of two radii.
    sumsq = (c1[2]+c2[2])*(c1[2]+c2[2])

    # This is when they intersect.
    return dsq <= sumsq

# Returns true if the subset declared in items of cranes doesn't have a pair of intersecting
# cranes.
def valid(cranes, items):

    # Go through all pairs.
    for i in range(len(items)):
        for j in range(i+1, len(items)):

            # If we get here, we found 2 that are too close.
            if intersect(cranes[items[i]], cranes[items[j]]):
                return False

    # Okay if we get here.
    return True

# Returns the area of the subset of circles in items (divided by pi).
def area(cranes, items):

    res = 0

    # Go through all pairs.
    for i in range(len(items)):

        # This times pi is the area of the circle...
        res += cranes[items[i]][2]*cranes[items[i]][2]

    return res

# Process cases.
nC = int(input())
for loop in range(nC):

    # Read in cranes.
    n = int(input())
    cranes = []
    for i in range(n):
        cranes.append([int(x) for x in input().split()])

    # Try each subset.
    res = 0
    for mask in range(1,1<<n):

        # Get list of items in this subset.
        items = getBits(mask)

        # If there's no intersection, consider it.
        if valid(cranes, items):
            res = max(res, area(cranes, items))

    # Ta da!
    print(res)
