WITH RECURSIVE search(dst_ap, depth, path) AS (
    -- everywhere you can fly from starting airport
    SELECT dst_ap, 1, ARRAY[src_ap, dst_ap]
    FROM route
    WHERE airline = 'WN' -- Southwest
      AND src_ap = 'IAD'
  UNION ALL
    -- everywhere you can fly from previous airport
    SELECT r.dst_ap, depth + 1, path || r.dst_ap
    FROM search AS s -- from the work table
      JOIN route AS r ON s.dst_ap = r.src_ap
    WHERE r.airline = 'WN' -- Southwest
      AND depth < 3
      AND NOT r.dst_ap = ANY(path)  -- no cycles
)
SELECT * FROM search
ORDER BY depth, dst_ap;
