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

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

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

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

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

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

l.s = b
a.o = h
a.p = k
b.s = l
k.o = h
k.p = a
h.s = l
assert a.o.s.s.txt == "b"