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

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

b = A("b")
e = B("e")
j = B("j")
g = B("g")
h = B("h")

b.w = h
e.z = j
j.z = h
g.z = e
h.z = e
assert b.w.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

b = A("b")
e = B("e")
j = B("j")
g = B("g")
h = B("h")

b.w = h
e.z = j
j.z = h
g.z = e
h.z = e
assert b.w.z.z.txt == "j"