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

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

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

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

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

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

k.r = l
k.p = l
b.o = k
b.s = k
i.o = l
i.s = l
l.r = k
l.p = k
assert k.p.p.r.r.txt == "k"