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

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

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

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

g = A("g")
f = B("f")
b = C("b")
c = D("c")

g.w = b
f.z = c
b.o = c
c.o = f
c.z = f
assert c.o.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

g = A("g")
f = B("f")
b = C("b")
c = D("c")

g.w = b
f.z = c
b.o = c
c.o = f
c.z = f
assert c.o.z.z.txt == "f"