Here's how you get all comments:
$comments = qa_db_read_one_value(
qa_db_query_sub(
"SELECT COUNT(postid) FROM ^posts WHERE (parentid=# OR parentid IN (SELECT postid FROM ^posts WHERE parentid=#)) AND type='C'",
$postid,$postid
)
);
Then all you need to do is run this over each q_list_item and change the output accordingly.