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

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

a = A("a")
l = B("l")
e = A("e")
m = A("m")

a.p = l
l.u = a
e.p = l
m.p = l
assert e.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

a = A("a")
l = B("l")
e = A("e")
m = A("m")

a.p = l
l.u = a
e.p = l
m.p = l
assert e.p.u.p.txt == "l"