Thanks, will be better.
There it will be ```e.coeff(t)``` and shouldn't there be condition on q[n] making 1 as it will every time make q[n]=1.
Having else condition before making q[n]=1 will do it.