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

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

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

k = A("k")
a = B("a")
f = C("f")
h = A("h")
c = B("c")
d = C("d")
g = B("g")
m = C("m")
i = C("i")
j = C("j")

k.p = h
a.o = d
a.x = k
f.z = i
h.p = k
c.o = f
c.x = k
d.z = j
g.o = j
g.x = k
m.z = j
i.z = m
j.z = d
assert k.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

k = A("k")
a = B("a")
f = C("f")
h = A("h")
c = B("c")
d = C("d")
g = B("g")
m = C("m")
i = C("i")
j = C("j")

k.p = h
a.o = d
a.x = k
f.z = i
h.p = k
c.o = f
c.x = k
d.z = j
g.o = j
g.x = k
m.z = j
i.z = m
j.z = d
assert k.p.p.p.txt == "h"