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

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

g = A("g")
b = B("b")
n = A("n")
d = B("d")

g.z = b
b.w = d
b.o = d
n.z = b
d.w = b
d.o = b
assert d.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

g = A("g")
b = B("b")
n = A("n")
d = B("d")

g.z = b
b.w = d
b.o = d
n.z = b
d.w = b
d.o = b
assert d.o.w.o.txt == "b"