set optimization with linked list works for query 3 with a lot of manual parts