perl -ne 'print if ($seen{$_} .= @ARGV && /^Query:/) =~ /10$/' fileA fileB > output