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

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

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

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

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

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

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

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

n.p = d
d.u = c
j.z = a
j.y = b
b.u = n
c.p = b
a.z = j
a.y = b
m.z = j
m.y = d
f.z = m
f.y = d
assert j.z.z.z.txt == "a"