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

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

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

l = A("l")
e = B("e")
m = C("m")
j = C("j")
h = C("h")
d = A("d")
n = B("n")

l.p = h
l.x = d
e.z = d
e.t = l
e.p = n
m.w = l
j.w = d
h.w = d
d.p = h
d.x = l
n.z = l
n.t = l
n.p = e
assert n.t.x.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.x: A = None
        self.txt = txt

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

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

l = A("l")
e = B("e")
m = C("m")
j = C("j")
h = C("h")
d = A("d")
n = B("n")

l.p = h
l.x = d
e.z = d
e.t = l
e.p = n
m.w = l
j.w = d
h.w = d
d.p = h
d.x = l
n.z = l
n.t = l
n.p = e
assert n.t.x.p.w.p.txt == "h"