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

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

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

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

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

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

l.p = j
j.o = b
b.o = j
m.p = b
assert m.p.o.o.o.txt == "j"