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

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

l = A("l")
h = B("h")
n = B("n")
b = B("b")
m = A("m")
d = A("d")
g = A("g")

l.p = h
h.y = m
n.y = l
b.y = l
m.p = n
d.p = b
g.p = b
assert l.p.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
n = B("n")
b = B("b")
m = A("m")
d = A("d")
g = A("g")

l.p = h
h.y = m
n.y = l
b.y = l
m.p = n
d.p = b
g.p = b
assert l.p.y.p.y.txt == "l"