'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
for i in range(int(raw_input())):
	n = int(raw_input())
	if n < 3:
		print n * n * n
		continue
	print n * n * n - (n-2) ** 3