Generalizing for arbitrary d, q