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

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

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

k.o = i
l.r = i
l.s = i
i.o = k
m.r = k
m.s = k
c.r = i
c.s = k
d.r = k
d.s = k
assert d.s.o.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.r: A = None
        self.s: A = None
        self.txt = txt

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

k.o = i
l.r = i
l.s = i
i.o = k
m.r = k
m.s = k
c.r = i
c.s = k
d.r = k
d.s = k
assert d.s.o.o.o.o.txt == "k"