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

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

g = A("g")
m = B("m")
b = A("b")
f = B("f")
e = B("e")
l = A("l")

g.y = l
g.w = b
m.z = l
b.y = l
b.w = l
f.z = g
e.z = g
l.y = g
l.w = g
assert g.w.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: A = None
        self.txt = txt

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

g = A("g")
m = B("m")
b = A("b")
f = B("f")
e = B("e")
l = A("l")

g.y = l
g.w = b
m.z = l
b.y = l
b.w = l
f.z = g
e.z = g
l.y = g
l.w = g
assert g.w.y.y.y.y.txt == "g"