ra: make the p, q test more efficient