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

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

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

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

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

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

d.w = b
d.u = b
b.p = c
c.w = i
c.u = i
i.p = d
assert d.u.p.w.p.txt == "d"