Beware that for large input files, you are reading the entire list.txt for every entry in query.txt
There may be better ways to approach this, but it depends how much you need to know. If you just need to know that ABC (or whatever) has been repeated and you don't care what the first string part is, then you might be better with this:-