for t in xrange(int(raw_input())):
    sides = int(raw_input())
    inner = 0 
    if sides - 2 > 0: 
    	inner = sides-2
    if sides > 2: 
        print 8+(inner)*12+6*inner*inner
    else:
        print sides*sides*sides