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

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

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

l = A("l")
f = B("f")
d = C("d")
h = A("h")
c = B("c")
j = C("j")

l.s = j
f.z = d
f.o = c
d.r = j
d.s = c
h.s = j
c.z = j
c.o = f
j.r = d
j.s = c
assert c.z.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

l = A("l")
f = B("f")
d = C("d")
h = A("h")
c = B("c")
j = C("j")

l.s = j
f.z = d
f.o = c
d.r = j
d.s = c
h.s = j
c.z = j
c.o = f
j.r = d
j.s = c
assert c.z.s.z.txt == "j"