class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: D = None
        self.z: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

m = A("m")
h = B("h")
e = C("e")
f = D("f")
c = B("c")
a = D("a")

m.r = e
h.o = m
h.z = m
h.r = a
e.s = m
f.z = e
c.o = m
c.z = m
c.r = a
a.z = e
assert e.s.r.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: D = None
        self.z: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

m = A("m")
h = B("h")
e = C("e")
f = D("f")
c = B("c")
a = D("a")

m.r = e
h.o = m
h.z = m
h.r = a
e.s = m
f.z = e
c.o = m
c.z = m
c.r = a
a.z = e
assert e.s.r.s.r.s.txt == "m"