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

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

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

g = A("g")
a = B("a")
n = C("n")
d = A("d")
h = C("h")
b = A("b")
l = A("l")
i = B("i")
f = B("f")

g.x = d
a.z = f
a.s = h
n.p = d
d.x = l
h.p = d
b.x = g
l.x = b
i.z = a
i.s = n
f.z = i
f.s = h
assert d.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

g = A("g")
a = B("a")
n = C("n")
d = A("d")
h = C("h")
b = A("b")
l = A("l")
i = B("i")
f = B("f")

g.x = d
a.z = f
a.s = h
n.p = d
d.x = l
h.p = d
b.x = g
l.x = b
i.z = a
i.s = n
f.z = i
f.s = h
assert d.x.x.x.x.x.x.txt == "b"