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

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

c = A("c")
m = B("m")
k = A("k")
i = B("i")

c.r = k
c.y = k
m.o = i
k.r = c
k.y = c
i.o = m
assert m.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.y: A = None
        self.txt = txt

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

c = A("c")
m = B("m")
k = A("k")
i = B("i")

c.r = k
c.y = k
m.o = i
k.r = c
k.y = c
i.o = m
assert m.o.o.o.txt == "i"