"The Synoptic Problem": The close similarities not only in content but in the language used between Matthew, Mark, and Luke, make scholars think that there was some interplay between them, with one author borrowing from another. Although ancient sources say that Matthew wrote first, it would not make sense for Mark to clip off the Nativity story and the Passion narrative, tack on a different Passion narrative, edit out the long passages of Jesus's teaching, and insert the "Messianic secret" passages that are exclusive to him. Then there's the problem that Matthew and Luke have near-verbatim parallels on the teachings -- but set in entirely different points in the MML narrative of events.
To account for this, some writers have suggested a mysterious "Q" source (from the German quelle, "source") of Jesus's teachings, and proposed that Matthew and Luke used a combination of (a) Mark, (b) Q, and (c) their own individual sources. However, with one exception there is no evidence beyond those similarities that Q ever existed.
That exception is Papias's comment on Matthew having "written out the logia of the Lord in Aramaic." Logia is a Greek plural of logion, a word related to logos, "word," and usually taken to mean "saying, oracle, word in the sense of utterance." The apocryphal "Gospel of Thomas" is such a collection of logia, though usually considered an unorthodox one.
The problem is that Matthew as we have it is not a collection of logia but a narrative -- "The Life and Teachings of Jesus the Promised Messiah" might be how Matthew would title it if he were writing for publication today.
The solution to this, which I have seen in several sources and came up with independently before finding or being sent to those sources, is this:
1. Matthew puts together a collection of Jesus's teachings, no longer extant.
2. Mark writes out his Gospel, based largely on the reminiscences of the recently dead Peter. (This per Papias.) His purpose is to show Jesus as the Son of God and to fill the need for a sequential account of His life.
3. These two documents circulate through the early churches.
4. Luke begins his researches, intended at separating the wheat from the chaff on all the stories about Jesus that are circulating, some accurate and some wildly arcane. (One apocryphal Gospel a the story of Jesus's boyhood where a playmate of his kills a sparrow. Jesus picks up the sparrow, restores it to life, and causes the boy to fall dead.)
5. Some person, probably in Antioch, takes Mark and the Matthew-logia book, and comes up with the idea of fitting them together. As was considered entirely proper practice in the First Century, he reconstructs five long discourses of Jesus on specific subjects, at points Jesus was known to have taught on those subjects, by extracting the material on those subjects from Matthew-logia, inserting them and the remaining teachings at the appropriate points in the Mark narrative. He portrays Jesus as the promised Messiah, the fulfillment of prophecy. His book becomes known by Matthew's name, since he was the source of the teachings contained in it.
6. Luke independently uses Mark as the frame story, but researches out where Jesus probably taught the different logia which he has from Matthew's collection and from other research, and fits them into his story at those points. Luke is known to have becomes friends with Mary the mother of Jesus, and presumably got the Annunciation, Nativity, and Visit to the Temple stories from her, along with some other material. Luke stresses Jesus as a compassionate teacher and healer.
7. As time passes, the "Matthew logia" book is pretty well discarded, since its contents are incorporated in two narrative gospels. "Matthew" becomes the name of the gospel containing all the logia; Luke, which contains most of them and separate exclusive material, is known by its author's name already. Mark remains in circulation, since his narrative has a special focus not shared by the two men who used his version as a framework for their own.