This version of St. Sophia was built around the same time as Istanbul's Hagia Sofia -- around 550. But the "current" structure is the fifth place of worship on this site. The others were destroyed by invaders. It was converted to a mosque under the Ottomans and then abandoned in the 1800s. It was restored in the 1900s. The name of the church actually comes from the greek phrase for "holy wisdom," not from St. Sofia, but that has not prevented the city from adopting St. Sofia as its symbol.
The story of St. Sofia is certainly catchier than that of holy wisdom. Sofia was a widow with three daughters: Faith, Hope, and Charity. The Romans tortured and killed Sophia's daughters in an attempt to get Sofia to renounce her Christian faith. Faith, twelve, was scourged but went unharmed when boiling pitch was poured on her and had to be beheaded; Hope, ten, and Charity, nine, were also beheaded after emerging unscathed, from a furnace. Sofia buried them and then died three days later while weeping at their graves.