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

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

e = A("e")
d = B("d")
b = B("b")

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

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

e = A("e")
d = B("d")
b = B("b")

e.u = b
e.w = d
d.p = b
b.p = d
assert e.u.p.p.txt == "b"