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

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

l = A("l")
a = B("a")
c = B("c")
b = A("b")

l.w = b
a.p = c
a.u = c
c.p = a
c.u = a
b.w = l
assert c.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

l = A("l")
a = B("a")
c = B("c")
b = A("b")

l.w = b
a.p = c
a.u = c
c.p = a
c.u = a
b.w = l
assert c.p.u.p.txt == "a"