Pelicans seem to evolve from pterosaurs but ostriches seem to have come from theropods. Since those are both birds, I would guess pterosaurs and theropods are just as closely related as pelicans and ostriches.
https://evolution.berkeley.edu/evolibrary/article/evograms_0...
https://blogs.scientificamerican.com/tetrapod-zoology/50-mil...
Because pterosaurs have no living descents, and all birds descended from therapod dinosaurs (even if birds were already widespread before the end of the Cretaceous).