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

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

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

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

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

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

d.p = k
k.w = b
k.o = d
b.w = k
b.o = d
assert k.w.w.o.txt == "d"