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

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

b = A("b")
m = B("m")
l = B("l")
f = A("f")

b.p = m
b.o = m
m.q = l
m.r = l
l.q = m
l.r = m
f.p = l
f.o = m
assert m.q.q.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.o: B = None
        self.txt = txt

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

b = A("b")
m = B("m")
l = B("l")
f = A("f")

b.p = m
b.o = m
m.q = l
m.r = l
l.q = m
l.r = m
f.p = l
f.o = m
assert m.q.q.r.r.txt == "m"