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

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

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

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

f = A("f")
m = B("m")
e = C("e")
d = D("d")

f.o = m
f.z = d
f.s = d
f.p = e
m.x = f
m.v = f
e.r = m
d.z = e
assert d.z.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.z: D = None
        self.s: D = None
        self.p: C = None
        self.txt = txt

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

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

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

f = A("f")
m = B("m")
e = C("e")
d = D("d")

f.o = m
f.z = d
f.s = d
f.p = e
m.x = f
m.v = f
e.r = m
d.z = e
assert d.z.r.v.txt == "f"