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

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

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

f = A("f")
n = B("n")
j = C("j")
g = C("g")
l = C("l")
a = C("a")
d = A("d")
m = B("m")
b = C("b")

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

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

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

f = A("f")
n = B("n")
j = C("j")
g = C("g")
l = C("l")
a = C("a")
d = A("d")
m = B("m")
b = C("b")

f.p = d
f.z = d
f.s = m
n.p = j
j.s = f
g.s = d
l.s = f
a.s = d
d.p = f
d.z = f
d.s = m
m.p = l
b.s = d
assert f.z.s.p.s.z.z.txt == "f"