'''
# 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(input()):
	n = input()
	s = n*n
	if n>1:
		s*=2
	if n*(n-2)>0:
		s+=2*n*(n-2)
		s+=2*((n-2)**2)
	print s