This is not a good idea on a live system; there is no programmatic interface for you to use to access the postfix queue while postfix is running. You can stop Postfix, and then use postsuper to delete all offending messages.
...but the idea is here:
# change directory to postfix's queue directory
cd $(postconf -h queue_directory)/active
# loop over queue files
for i in * ; do
# postcat e file, grep for subject "test" and if found
# run postsuper -d to delete queue'd message
postcat $i |grep -q '^Subject: test' && echo postsuper -d $i
You can do similar for the hold and deferred directories, in a loop if desired. Remove the echo above to actually delete - currently the script only outputs what it would do.
Let me guess - is your queue filled up with backscatter for invalid recipients and your server is not doing recipient validation?