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

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

m = A("m")
i = B("i")
c = A("c")
k = B("k")
j = A("j")
l = B("l")
f = B("f")
g = A("g")

m.s = f
i.r = f
c.s = l
k.r = i
j.s = f
l.r = f
f.r = i
g.s = l
assert g.s.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.r: B = None
        self.txt = txt

m = A("m")
i = B("i")
c = A("c")
k = B("k")
j = A("j")
l = B("l")
f = B("f")
g = A("g")

m.s = f
i.r = f
c.s = l
k.r = i
j.s = f
l.r = f
f.r = i
g.s = l
assert g.s.r.r.txt == "i"