def number_of_pieces_exposed(n):
    if n <= 0:
        return 0
    elif n == 1:
        return 1
    else:
        return 8 + 12 * (n - 2) + 6 * (n ** 2 - 4 - 4 * (n - 2))


def read_input():
    t = int(raw_input())
    cases = []
    for i in range(0, t, 1):
        cases.append(int(raw_input()))
    return cases


input_arr = read_input()
for i in input_arr:
    print number_of_pieces_exposed(i)