Tamas,
You are thinking of how the letters look today.
The development that I am referring to occurred in the Aramaic script between the 7th and 5th centuries b.c.e.
The Mem looked similar to a modern cursive Kaf with the addition of a vertical stroke crossing the top near the left side. As time went on the vertical stroke became curved towards the left when it was followed by another letter. In the final position the vertical stroke began to lengthen until eventually it met the bottom part of the Kaf-like part thus forming a closed letter that resembles the present day final Mem.
As for Qof, in the earliest Aramaic script is resembled the Greek letter Psi. As time went on the left hand “tine” began to be written as a short vertical stroke, which gradually curved slightly to the left making the letter appear similar to a modern day Qof with a serif-like stroke at the upper left, the main vertical stroke was not the final strike but the penultimate stroke (in other words, the Qof was written with three strokes: the top stroke that went to the right and began to curve downward, the main vertical stroke, and the serif-like stroke on the upper left). Because that final little stroke was at the top of the letter it never developed the curve to the left that happens when moving from the end of the final stroke at the bottom of letters as the scribe moved his stylus upwards to the left to begin writing the next letter.
There are numerous books on the development of the Aramaic script from the old Canaanite/Hebrew script. The late professor David Diringer of the Museum of the Alphabet in Tel Aviv wrote some very informative ones. Ada Yardeni’s “The Book of Hebrew Script” (Arta, Jerusalem 1997) [revised and expanded from the original 1991 Hebrew edition ”Sefer Haktav Ha‘ivri] also has some illustrations of the development of the script and Gesenius’s Hebrew Grammar has a chart showing some of the development.
Avraham