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

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

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

b.o = d
m.s = j
m.p = d
d.o = b
j.s = m
j.p = d
assert d.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

b.o = d
m.s = j
m.p = d
d.o = b
j.s = m
j.p = d
assert d.o.o.o.txt == "b"