I think the solution vino has given is perfect.if you really know the line number then put that line no just before p and line no+1 just before q.
like
sed -n '4q;3p' test.txt
that sounds strange requirement, i guess u r trying to run that command if so
run below script if you just want to print that line replace exec $line with echo "$line".
But i think sed solution is superior.
echo "enter line no"
read x
count=1
while read line
do
if [ $count -eq $x ]
then
exec $line
exit 0
fi
count=`expr $count + 1`
done <test.txt