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

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

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

g = A("g")
d = B("d")
j = C("j")
a = A("a")
b = B("b")
f = B("f")
e = C("e")

g.o = d
g.y = j
d.x = f
j.z = d
a.o = d
a.y = j
b.x = d
f.x = b
e.z = d
assert b.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.y: C = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
j = C("j")
a = A("a")
b = B("b")
f = B("f")
e = C("e")

g.o = d
g.y = j
d.x = f
j.z = d
a.o = d
a.y = j
b.x = d
f.x = b
e.z = d
assert b.x.x.x.x.x.txt == "f"