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

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

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

e.p = c
e.y = m
j.p = m
d.p = m
a.p = e
h.p = c
h.y = c
m.p = c
m.y = e
c.p = h
c.y = h
assert d.p.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: A = None
        self.txt = txt

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

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

e.p = c
e.y = m
j.p = m
d.p = m
a.p = e
h.p = c
h.y = c
m.p = c
m.y = e
c.p = h
c.y = h
assert d.p.p.y.txt == "h"