Let's say we have $(q, \dot{q})$ as the generalised coordinate and generalised velocity. If we have a Lagrangian given by $$L=Aq\dot{q}+Bq$$ where $A$ and $B$ are constants that give the right units to the Lagrangian, then the canonical momentum $p$ we use to perform the Legendre transformation to get the Hamiltonian is
$$p=\frac{\partial L}{\partial \dot{q}}=Aq.$$ But then $p$ and $q$ are not independent variables as $$\frac{\partial p}{\partial q}=\frac{\partial}{\partial q} Aq=A\neq0.$$
What am I doing wrong here?