If A is not equal to B, because your question is not clear, I will divide it into two situations:
1. If BQ=b, then b` q = h-b.
Imagine a cylinder as a paper tube, and cut it along AA' with BB' as the axis. After cutting, point a corresponds to m, and A' corresponds to n.
Then the distance from B' to a on the plane is B'm:πr, in the right-angled trapezoid B'mpq, MP = A, B'q = H-B,
We are not afraid to assume H-B > A the shortest pq of a sphere is √ [(π r) 2+(h-b-a) 2].
2. If B`Q=b, we don't set b>a, and the shortest pq of the sphere is √ [(π r) 2+(b-a) 2].
Here, h-b and A or B and A, which is bigger or smaller, does not affect PQ's pitch.