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

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

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

i = A("i")
m = B("m")
l = C("l")
d = A("d")
k = C("k")
g = C("g")

i.x = m
i.o = m
m.s = d
m.r = g
l.z = i
d.x = m
d.o = m
k.z = i
g.z = i
assert i.o.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: B = None
        self.txt = txt

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

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

i = A("i")
m = B("m")
l = C("l")
d = A("d")
k = C("k")
g = C("g")

i.x = m
i.o = m
m.s = d
m.r = g
l.z = i
d.x = m
d.o = m
k.z = i
g.z = i
assert i.o.s.x.s.txt == "d"