Section 5B. Subject to the provisions of section three B a motor vehicle owned by a resident serving in the military service of the United States which was purchased by said resident in another state and registered therein, may be operated on the ways of this commonwealth without registration under this chapter for a period of thirty days. At the expiration of said thirty day period, said motor vehicle shall be registered in accordance with the provisions of this chapter.