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[2a_{1} + (p-1)d] / q/2[2a_{1}+(q-1)d] = P^{2}/Q^{2}

^{=> }p[2a_{1} + (p-1)d] / q[2a_{1}+(q-1)d] = P^{2}/Q^{2} --------------------(1)

Now a6/a21 = a_{1} + (6-1)d / a_{1 }+ (21-1)d

=> a_{6}/a_{21} = a_{1} + 5d / a_{1 }+ 20d -------------(2)

Now find the ratio using equation (1) and (2)