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

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

h = A("h")
l = B("l")
b = A("b")

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

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

h = A("h")
l = B("l")
b = A("b")

h.p = b
l.o = b
b.p = h
assert l.o.p.p.txt == "b"