write sameroot method and test