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

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

m = A("m")
b = B("b")
a = A("a")
e = A("e")
d = B("d")
h = B("h")

m.w = b
b.r = d
a.w = d
e.w = b
d.r = h
h.r = d
assert h.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

m = A("m")
b = B("b")
a = A("a")
e = A("e")
d = B("d")
h = B("h")

m.w = b
b.r = d
a.w = d
e.w = b
d.r = h
h.r = d
assert h.r.r.r.r.r.txt == "d"