The Küçük (Little) Haghia Sophia began life as a church, built as SS. Sergius and Bacchus, begun by Justian and his Empress Theodora in 527, five years before the (“Big”) Haghia Sophia, which has a gallery of its own: Aya Sofia. The church was converted into a mosque in the early 16th century. Its patron at the time was Hüseyin Ağa, who was Kapıağası – Chief of the White Eunuchs under Beyazit II. His tomb is still in the garden outside.
From the Catholic Encyclopaedia on internet: [SS. Sergius and Bacchus were] martyrs, d. in the Diocletian persecution in Coele-Syria about 303. Their martyrdom is well authenticated by the earliest martyrologies and by the early veneration paid them, as well as by such historians as Theodoret. They were officers of troops on the frontier, Sergius being primicerius, and Bacchus secundarius. According to the legend, there were high in esteem of the Caesar Maximianus on account of their bravery, but this favour was turned into hate when they acknowledged their Christian faith. When examined under torture they were beaten so severely with thongs that Bacchus died under the blows. Sergius, though, had much more suffering to endure; among other tortures, as the legend relates, he had to run eighteen miles in shoes which were covered on the soles with sharp-pointed nails that pierced through the foot. He was finally beheaded. In the East, Sergius and Bacchus were universally honoured. Christian art represents the two saints as soldiers in military garb with branches of palm in their hands. Their feast is observed on 7 October.