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

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

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

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

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

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

k.w = h
d.o = b
h.o = d
b.o = d
m.w = b
assert h.o.o.o.o.txt == "b"