int main()
{
int a, query, in, n, *b, *sum;
scanf("%d",&query);
sum = malloc(query * sizeof(int));
/* do some checks if the malloc was successful */
for(a = 0; a < query; a++)
{
scanf("%d",&in) ; /* you should check if scan has returned 1 */
b = malloc(in * sizeof(int)); /* and again check against any allocation errors */
for(n = 0; n < in; n++)
{
b[n] = 1+7*(n)+6*(n)*(n-1)+(n)*(n-1)*(n-2);
sum[a] = sum[a] + b[n];
}
free(b);
}
/* the rest */