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

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

class C:
    def __init__(self, txt: str):
        self.u: A = None
        self.o: B = None
        self.txt = txt

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

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

f.o = e
f.y = a
m.s = a
e.u = f
e.o = m
a.p = m
a.x = f
a.z = f
a.t = f
assert a.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: A = None
        self.o: B = None
        self.txt = txt

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

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

f.o = e
f.y = a
m.s = a
e.u = f
e.o = m
a.p = m
a.x = f
a.z = f
a.t = f
assert a.p.s.p.s.txt == "a"