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

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

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

l.p = c
l.u = b
b.z = l
b.s = f
c.p = l
c.u = f
f.z = l
f.s = b
assert l.p.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: B = None
        self.txt = txt

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

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

l.p = c
l.u = b
b.z = l
b.s = f
c.p = l
c.u = f
f.z = l
f.s = b
assert l.p.u.s.txt == "b"