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

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

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

m = A("m")
g = B("g")
j = C("j")
a = C("a")
d = B("d")
k = B("k")
e = A("e")
n = A("n")
h = A("h")

m.w = d
g.z = j
g.o = e
j.x = d
j.p = a
a.x = d
a.p = j
d.z = j
d.o = e
k.z = j
k.o = n
e.w = g
n.w = g
h.w = g
assert j.p.p.p.p.p.p.p.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
j = C("j")
a = C("a")
d = B("d")
k = B("k")
e = A("e")
n = A("n")
h = A("h")

m.w = d
g.z = j
g.o = e
j.x = d
j.p = a
a.x = d
a.p = j
d.z = j
d.o = e
k.z = j
k.o = n
e.w = g
n.w = g
h.w = g
assert j.p.p.p.p.p.p.p.x.z.txt == "j"