I am stuck in "goblet of fire " problem ...could any one help me?

here is the question

This year Triwizard Championship is being organized in Hogwarts. For the final task, each of the candidates was given a magic number k. With this given number, the candidates have to answer the number of possible 3×3 magic squares that can be formed such that the magic of the square is k.

But since it’s an event at Hogwarts, their definition of Magic square is different. The features of Hogwart’s Magic Square with a magic number k are given as :

Sum of all the numbers in each row is equal to k
Sum of all the numbers in each column is equal to k
Sum of all the numbers in each diagonal is equal to k
All the numbers in the magic square are in the range of 1 to k (including both)
There should be at least 1 odd number in the Hogwart’s Magic Square
All the numbers need not be distinct.
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
Each test case consists of a single integer k.
For each test case, output a single integer, the number of magic squares possible.
Sample Input:
Sample Output:

The middle element will always be k/3. Now let the top right and top left elements be x and y, and find the values of all other elements through your row,column and diagonal relationships. Now, find all the values of x and y such that all elements have a positive value lesser than k. You will end up at some formula. I am sure some easier way is there, but I can’t find it.

Look at the submissions for the exact formula, reply if you don’t understand.