Perhaps some refactoring is in order here: `if e.has(t)` and following become
```
tpart = e.as_independent(t, Mul)[1]
if tpart is not S.One:
  for i in Mul.make_args(tpart):
    if i.has(exp):
        b, e = i.as_base_exp()
        co = b.coeff(t)
        if co and not co.has(t) and co.has(I):
            p[n] = 1
            continue
  q[n] = 1
```