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

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

a = A("a")
h = B("h")
e = B("e")
i = B("i")
l = A("l")
d = A("d")
m = B("m")
j = A("j")
n = A("n")
c = A("c")

a.p = j
h.y = i
h.z = e
e.y = h
e.z = m
i.y = e
i.z = m
l.p = d
d.p = l
m.y = h
m.z = e
j.p = n
n.p = j
c.p = d
assert j.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.y: B = None
        self.z: B = None
        self.txt = txt

a = A("a")
h = B("h")
e = B("e")
i = B("i")
l = A("l")
d = A("d")
m = B("m")
j = A("j")
n = A("n")
c = A("c")

a.p = j
h.y = i
h.z = e
e.y = h
e.z = m
i.y = e
i.z = m
l.p = d
d.p = l
m.y = h
m.z = e
j.p = n
n.p = j
c.p = d
assert j.p.p.p.txt == "n"