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

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

m = A("m")
c = B("c")
b = A("b")
h = B("h")
d = A("d")

m.o = c
c.r = m
c.p = h
b.o = c
h.r = m
h.p = c
d.o = h
assert m.o.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

m = A("m")
c = B("c")
b = A("b")
h = B("h")
d = A("d")

m.o = c
c.r = m
c.p = h
b.o = c
h.r = m
h.p = c
d.o = h
assert m.o.p.p.p.p.txt == "c"