class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.z: 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 = A("a")

l.u = a
l.z = b
b.p = a
a.u = l
a.z = b
assert a.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.z: 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 = A("a")

l.u = a
l.z = b
b.p = a
a.u = l
a.z = b
assert a.z.p.z.txt == "b"