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

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

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

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

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

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

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

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

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