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

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

i = A("i")
l = B("l")
c = B("c")
h = B("h")
b = B("b")
m = A("m")
d = B("d")
e = B("e")
f = B("f")
a = A("a")

i.r = a
l.s = i
c.s = i
h.s = a
b.s = i
m.r = i
d.s = m
e.s = i
f.s = i
a.r = m
assert m.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

i = A("i")
l = B("l")
c = B("c")
h = B("h")
b = B("b")
m = A("m")
d = B("d")
e = B("e")
f = B("f")
a = A("a")

i.r = a
l.s = i
c.s = i
h.s = a
b.s = i
m.r = i
d.s = m
e.s = i
f.s = i
a.r = m
assert m.r.r.r.r.txt == "i"