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

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

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

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

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

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

k.s = i
b.t = i
b.r = m
i.t = m
i.r = b
m.t = i
m.r = b
l.s = m
assert m.r.r.t.r.r.txt == "m"