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

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

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

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

c = A("c")
i = B("i")
e = C("e")
b = D("b")
m = B("m")

c.s = b
i.t = m
i.x = c
e.r = c
b.z = c
m.t = i
m.x = c
assert c.s.z.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

c = A("c")
i = B("i")
e = C("e")
b = D("b")
m = B("m")

c.s = b
i.t = m
i.x = c
e.r = c
b.z = c
m.t = i
m.x = c
assert c.s.z.s.z.s.txt == "b"