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

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

m = A("m")
i = B("i")
b = A("b")
d = A("d")

m.u = i
m.p = i
i.p = m
b.u = i
b.p = i
d.u = i
d.p = i
assert b.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
b = A("b")
d = A("d")

m.u = i
m.p = i
i.p = m
b.u = i
b.p = i
d.u = i
d.p = i
assert b.p.p.p.txt == "i"