you can add break; statement after finding query. No need to iterate through all remaining elements