Your question is a bit not clear.But what I understand showing you.
Given a1,a2,a3............. be terms of an AP
Let common difference is d
(a1+a2+a3+a4...............ap)/(a1+a2+a3+a4................aq)=p^2/Q^2
p/2[2a1 + (p-1)d] / q/2[2a1+(q-1)d] = P2/Q2
=> p[2a1 + (p-1)d] / q[2a1+(q-1)d] = P2/Q2 --------------------(1)
Now a6/a21 = a1 + (6-1)d / a1 + (21-1)d
=> a6/a21 = a1 + 5d / a1 + 20d -------------(2)
Now find the ratio using equation (1) and (2)