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

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

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

i = A("i")
j = B("j")
m = C("m")
c = C("c")
a = C("a")
f = C("f")
g = A("g")
n = A("n")

i.p = m
j.x = a
j.p = i
m.z = i
m.y = c
m.w = c
c.z = g
c.y = a
c.w = m
a.z = i
a.y = c
a.w = m
f.z = i
f.y = m
f.w = m
g.p = c
n.p = f
assert j.p.p.y.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

i = A("i")
j = B("j")
m = C("m")
c = C("c")
a = C("a")
f = C("f")
g = A("g")
n = A("n")

i.p = m
j.x = a
j.p = i
m.z = i
m.y = c
m.w = c
c.z = g
c.y = a
c.w = m
a.z = i
a.y = c
a.w = m
f.z = i
f.y = m
f.w = m
g.p = c
n.p = f
assert j.p.p.y.z.p.txt == "c"