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

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

l = A("l")
b = B("b")
a = B("a")
n = B("n")
c = B("c")
m = B("m")
e = A("e")
i = B("i")

l.y = b
b.p = l
a.p = l
n.p = e
c.p = l
m.p = l
e.y = n
i.p = e
assert c.p.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

l = A("l")
b = B("b")
a = B("a")
n = B("n")
c = B("c")
m = B("m")
e = A("e")
i = B("i")

l.y = b
b.p = l
a.p = l
n.p = e
c.p = l
m.p = l
e.y = n
i.p = e
assert c.p.y.p.y.txt == "b"