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

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

i = A("i")
b = B("b")
k = A("k")
l = B("l")
c = B("c")

i.o = k
b.p = i
b.o = l
k.o = i
l.p = i
l.o = b
c.p = i
c.o = b
assert c.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.p: A = None
        self.o: B = None
        self.txt = txt

i = A("i")
b = B("b")
k = A("k")
l = B("l")
c = B("c")

i.o = k
b.p = i
b.o = l
k.o = i
l.p = i
l.o = b
c.p = i
c.o = b
assert c.o.o.o.txt == "b"