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

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

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

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

e.r = h
e.z = l
d.r = m
d.p = e
d.o = h
m.z = l
m.p = j
h.r = e
h.z = c
c.z = l
c.p = j
j.r = c
j.p = n
j.o = h
f.z = l
f.p = b
b.r = m
b.p = e
b.o = n
n.r = h
n.z = m
l.z = c
l.p = d
assert j.r.z.z.z.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: C = None
        self.txt = txt

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

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

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

e.r = h
e.z = l
d.r = m
d.p = e
d.o = h
m.z = l
m.p = j
h.r = e
h.z = c
c.z = l
c.p = j
j.r = c
j.p = n
j.o = h
f.z = l
f.p = b
b.r = m
b.p = e
b.o = n
n.r = h
n.z = m
l.z = c
l.p = d
assert j.r.z.z.z.p.r.txt == "m"